wrong_number_of_type_arguments_extension
The extension '{0}' is declared with {1} type parameters, but {2} type arguments were given.
Description
#The analyzer produces this diagnostic when an extension that has type parameters is used and type arguments are provided, but the number of type arguments isn't the same as the number of type parameters.
Example
#The following code produces this diagnostic because the extension E
is declared to have a single type parameter (T
), but the extension override has two type arguments:
extension E<T> on List<T> {
int get len => length;
}
void f(List<int> p) {
E<int, String>(p).len;
}
Common fixes
#Change the type arguments so that there are the same number of type arguments as there are type parameters:
extension E<T> on List<T> {
int get len => length;
}
void f(List<int> p) {
E<int>(p).len;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.