non_covariant_type_parameter_position_in_representation_type
An extension type parameter can't be used in a non-covariant position of its representation type.
Description
#The analyzer produces this diagnostic when a type parameter of an extension type is used in a non-covariant position in the representation type of that extension type.
Example
#The following code produces this diagnostic because the type parameter T
is used as a parameter type in the function type void Function(T)
, and
parameters are not covariant:
dart
extension type A<T>(void Function(T) f) {}
Common fixes
#Remove the use of the type parameter:
dart
extension type A(void Function(String) f) {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。