TS2636
error TS2636: Type ‘
Func<super-T>
‘ is not assignable to type ‘Func<sub-T>
‘ as implied by variance annotation. Type ‘super-T
‘ is not assignable to type ‘sub-T
‘.
Broken Code ❌
1 |
|
Fixed Code ✔️
Variance annotations on type variables must be consistent with their position. If a type variable is at output (read) position, it should be annotated with out
:
1 |
|
Alternatively, you can annotate it with both in
and out
(i.e. as invariant):
1 |
|