Created
June 23, 2023 10:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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