Skip to content

Instantly share code, notes, and snippets.

@ktkk
Created June 23, 2023 10:35
Show Gist options
  • Save ktkk/d399a109b8123d85d3c96b747fefbdaa to your computer and use it in GitHub Desktop.
Save ktkk/d399a109b8123d85d3c96b747fefbdaa to your computer and use it in GitHub Desktop.
Type inference breaks(?) when using a list of records and a callback function
typedef MyCallback<T> = void Function(T? value);
typedef MyRecord<T> = (String title, T value);
class MyRecordClass<T> {
const MyRecordClass(this.title, this.value);
final String title;
final T value;
}
class MyClass<T> {
const MyClass({required this.records, required this.callback});
// final List<MyRecordClass<T>> records;
final List<MyRecord<T>> records;
final MyCallback<T> callback;
}
final myClass = MyClass(
records: [("First", 1), ("Second", 2), ("Third", 3)],
callback: (value) => print(value),
// ^here: inferred as 'Object?'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment