Open saddig opened 2 years ago
It's not supposed to matter.
The true issue I would say is what isar
does with the typdef. It's using typedefs in a way that breaks the equality, where Id
!= int
I believe it'd be more logical to do:
@Id()
int id
instead of:
Id id
The reason why it is done this way is that
@collection
class Model {
Id id;
float floatProp;
List<byte> byteList;
List<short> shortList;
}
is much more readable than the previous
@collection
class Model {
@id
int id;
@size32
double floatProp;
@size8
List<int> byteList;
@size32
List<int> shortList;
}
and these typedefs cannot be used incorrectly. You can never try to create a double
id or @size32
String
.
Furthermore web and native targets have different Id
types. Id
is num
for web and int
for native targets.
I understand the desire, but it's not really a typedef anymore though.
I'd be happy to review a PR for this, but I don't plan on working on this.
For anyone struggling with this, see workaround here
It's not supposed to matter.
It actually does matter. Consider this example:
/// a.dart
class A {}
/// b.dart
import 'a.dart';
typedef B = A;
/// c.dart
import 'package:freezed_annotation/freezed_annotation.dart';
import 'b.dart';
part 'c.freezed.dart';
@freezed
class C with _$C {
const factory C(B b) = _C;
}
void main() {
final c = C(B());
print(c.b);
}
In this case, c.b
type is not properly resolved because freezed
generates _C
as:
mixin _$C {
A get b => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$CCopyWith<C> get copyWith => throw _privateConstructorUsedError;
}
But A
type is not imported (only B
is).
Describe the bug freezed's code generation changes the type of fields defined with a typedef type:
In Isar,
Id
is defined asRelated issue opened in Isar: https://github.com/isar/isar/issues/639
To Reproduce
order.freezed.dart:
Expected behavior I'd expect freezed to pass the type
Id
to the generated class instead of passingint
.Using: freezed: ^2.1.0+1 freezed_annotation: ^2.1.0
isar: 3.0.0-dev.14 isar_flutter_libs: 3.0.0-dev.14 isar_generator: 3.0.0-dev.14