Closed
Description
This is an old issue since Dart 1 and doesn't seem to have been fixed. #8741
This behavior is preventing the below API patterns from being efficiently implemented.
extension ListExtension<T> on List<T> {
void sortBy<T2 extends Comparable<T2>>(T2 Function(T element) f) {
this.sort((a, b) => f(a).compareTo(f(b)));
}
}
Trying to invoke this function
[1].sortBy((x) => x);
will cause error: int doesn't extend Comparable<int>
We need to change generics parameter to num
at every invocation site.
[1].sortBy<num>((x) => x);