instantiate_type_alias_expands_to_type_parameter
Type aliases that expand to a type parameter can't be instantiated.
Description
#The analyzer produces this diagnostic when a constructor invocation is found where the type being instantiated is a type alias for one of the type parameters of the type alias. This isn't allowed because the value of the type parameter is a type rather than a class.
Example
#The following code produces this diagnostic because it creates an instance
of A
, even though A
is a type alias that is defined to be equivalent to
a type parameter:
typedef A<T> = T;
void f() {
const A<int>();
}
Common fixes
#Use either a class name or a type alias defined to be a class, rather than a type alias defined to be a type parameter:
typedef A<T> = C<T>;
void f() {
const A<int>();
}
class C<T> {
const C();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。