Closed
Description
TypeScript Version: 4.1.0-dev.20201009 & 4.0.3
Search Terms: deferred conditional assignment not assignable to type
Code
const doSomething = <T extends boolean>(t: T) => {
const a: string = 'foo';
const b: string | undefined = 'bar';
const c: T extends true ? string : (string | undefined) = 'baz' as string;
return c;
}
Expected behavior:
(baz
as string) is assignable to c
as string
is assignable to both branches of the deferred conditional type.
Actual behavior:
The following error is emitted:
Type 'string' is not assignable to type 'T extends true ? string : string | undefined'.ts(2322)
Metadata
Metadata
Assignees
Labels
No labels