We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
baz
c
string
Actual behavior:
The following error is emitted:
Type 'string' is not assignable to type 'T extends true ? string : string | undefined'.ts(2322)
Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20201009#code/FAYw9gdgzgLgBAEzAZTAWwKYwBYEsIDmcAvHADwAqcGAHjBhAlHAEZhgA2GAhhAHwAKGAC44FAJQk+cAN7A4ccNHjdRsAE74ipAOQAzdjoDc8xZFis1MTYTgAfOAFdGGPfgwIScHS27rjpkoWIKJUtPSMzNaOGHAA-HAaWnCiAkm2Ds4Iru4Ikrq+AF4BCupYjuoQiiYAvkA
Related Issues: #39364 #39577
The text was updated successfully, but these errors were encountered:
Duplicate of #26933 ?
Sorry, something went wrong.
Yep, was unable to find it because i had explicitly searched for deferred.
Closing.
No branches or pull requests
TypeScript Version: 4.1.0-dev.20201009 & 4.0.3
Search Terms: deferred conditional assignment not assignable to type
Code
Expected behavior:
(
baz
as string) is assignable toc
asstring
is assignable to both branches of the deferred conditional type.Actual behavior:
The following error is emitted:
Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20201009#code/FAYw9gdgzgLgBAEzAZTAWwKYwBYEsIDmcAvHADwAqcGAHjBhAlHAEZhgA2GAhhAHwAKGAC44FAJQk+cAN7A4ccNHjdRsAE74ipAOQAzdjoDc8xZFis1MTYTgAfOAFdGGPfgwIScHS27rjpkoWIKJUtPSMzNaOGHAA-HAaWnCiAkm2Ds4Iru4Ikrq+AF4BCupYjuoQiiYAvkA
Related Issues: #39364 #39577
The text was updated successfully, but these errors were encountered: