wrong_number_of_type_arguments
The type '{0}' is declared with {1} type parameters, but {2} type arguments were given.
Description
#The analyzer produces this diagnostic when a type 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.
The analyzer also produces this diagnostic when a constructor is invoked and the number of type arguments doesn't match the number of type parameters declared for the class.
Examples
#The following code produces this diagnostic because C
has one type parameter but two type arguments are provided when it is used as a type annotation:
class C<E> {}
void f(C<int, int> x) {}
The following code produces this diagnostic because C
declares one type parameter, but two type arguments are provided when creating an instance:
class C<E> {}
var c = C<int, int>();
Common fixes
#Add or remove type arguments, as necessary, to match the number of type parameters defined for the type:
class C<E> {}
void f(C<int> x) {}
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.