rrousselGit/freezed

Type with typedef get changed by freezed

オープン

#753 opened on 2022/09/08

 (5 件のコメント) (1 件のリアクション) (1 人の担当者)Dart (300 件のフォーク)github user discovery
bughelp wanted

Repository metrics

Stars
 (2,177 個のスター)
PR merge metrics
 (平均マージ 25d 18h) (30d で 1 merged PR)

説明

Describe the bug freezed's code generation changes the type of fields defined with a typedef type:

In Isar, Id is defined as

/// Type to specify the id property of a collection.
typedef Id = int;

Related issue opened in Isar: https://github.com/isar/isar/issues/639

To Reproduce

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isar/isar.dart';

part 'order.freezed.dart';
part 'order.g.dart';

@Freezed(makeCollectionsUnmodifiable: false)
@Collection(ignore: {'copyWith'})
class Order with _$Order {
  factory Order({
    Id? localId,
    required String id,
     }) = _Order;

  factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json);
}

order.freezed.dart:

/// @nodoc
mixin _$Order {
  int? get localId => throw _privateConstructorUsedError;

Expected behavior I'd expect freezed to pass the type Id to the generated class instead of passing int.

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

コントリビューターガイド