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
type Func<in T> = () => T;

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
type Func<out T> = () => T;

Alternatively, you can annotate it with both in and out (i.e. as invariant):

1
type Func<in out T> = () => T;