wrong_number_of_type_arguments_constructor
The constructor '{0}.{1}' doesn't have type parameters.
Description
#The analyzer produces this diagnostic when type arguments are provided after the name of a named constructor. Constructors can't declare type parameters, so invocations can only provide the type arguments associated with the class, and those type arguments are required to follow the name of the class rather than the name of the constructor.
Example
#The following code produces this diagnostic because the type parameters
(<String>
) follow the name of the constructor rather than the name of the
class:
class C<T> {
C.named();
}
C f() => C.named<String>();
Common fixes
#If the type arguments are for the class' type parameters, then move the type arguments to follow the class name:
class C<T> {
C.named();
}
C f() => C<String>.named();
If the type arguments aren't for the class' type parameters, then remove them:
class C<T> {
C.named();
}
C f() => C.named();
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。