Closed
Description
Bug Report
π Search Terms
not assignable to the constraint of type
could be instantiated with a different subtype of constraint
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
Playground link with relevant code
π» Code
type A = () => void;
type B = () => void;
// error
function f1<T extends A | B>(value: T): T {
return () => value();
}
// ok
function f2<T extends A | B>(value: T): T extends A ? A : B {
return () => value();
}
π Actual behavior
The following error is happening with f1
but not f2
:
Type '() => void' is not assignable to type 'T'.
'() => void' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'B | A'.
π Expected behavior
Defining f1
should work fine.