Dart 3.3 extension types don't work with `dart_mappable`
Closed this issue · 1 comments
benthillerkus commented
Using the definition of the SimpleMapper custom Mapper as a reference:
/// An interface to define a custom mapper.
///
/// Implementation should extend this interface and implement the
/// [decode] and [encode] methods.
/// For a generic type with one or two generic type arguments, extend the
/// [SimpleMapper1] or [SimpleMapper2] interface instead, respectively.
///
/// {@category Custom Mappers}
abstract class SimpleMapper<T extends Object> extends _SimpleMapperBase<T> {
const SimpleMapper();
T decode(Object value);
Object? encode(T self);
@override
T _decode(Object value, DecodingContext context) {
return decode(value);
}
@override
Object? _encode(T value, EncodingContext context) {
return encode(value);
}
}
Extension types don't seem to extend Object
, so you cannot use them as the type parameter T
.
And because the return type of decode
has to be the same as T
, you cannot define the Mapper on the wrapped value instead.
benthillerkus commented
Ok, it turns out it does work, one just has to implement Object
on the extension type 🤦