rrousselGit/freezed

Type with typedef get changed by freezed

开放

#753 创建于 2022年9月8日

 (5 条评论) (1 个反应) (1 位负责人)Dart (300 个派生)github user discovery
bughelp wanted

仓库指标

星标
 (2,177 个星标)
PR 合并指标
 (平均合并 25天 18小时) (30 天内合并 1 个 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

贡献者指南