redirect_to_type_alias_expands_to_type_parameter
A redirecting constructor can't redirect to a type alias that expands to a type parameter.
Description
#The analyzer produces this diagnostic when a redirecting factory constructor redirects to a type alias, and the type alias expands to 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 the redirect to B<A>
is to a type alias whose value is T
, even though it looks like the value
should be A
:
class A implements C {}
typedef B<T> = T;
abstract class C {
factory C() = B<A>;
}
Common fixes
#Use either a class name or a type alias that is defined to be a class rather than a type alias defined to be a type parameter:
class A implements C {}
abstract class C {
factory C() = A;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。