Dart Analyze logoDart Analyze/
DRT-W1711

Wrong number of type parameters and type argumentsDRT-W1711

Major severityMajor
Bug Risk categoryBug Risk

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) {}