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:
extension type A<T>(void Function(T) f) {}
Common fixes
#Remove the use of the type parameter:
extension type A(void Function(String) f) {}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-4. View source or report an issue.