Skip to content
New issue

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

Values are not assignable to deferred conditional types even when they are assignable to both branches. #41009

Closed
s0 opened this issue Oct 9, 2020 · 2 comments

Comments

@s0
Copy link
Contributor

s0 commented Oct 9, 2020

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)

Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20201009#code/FAYw9gdgzgLgBAEzAZTAWwKYwBYEsIDmcAvHADwAqcGAHjBhAlHAEZhgA2GAhhAHwAKGAC44FAJQk+cAN7A4ccNHjdRsAE74ipAOQAzdjoDc8xZFis1MTYTgAfOAFdGGPfgwIScHS27rjpkoWIKJUtPSMzNaOGHAA-HAaWnCiAkm2Ds4Iru4Ikrq+AF4BCupYjuoQiiYAvkA

Related Issues: #39364 #39577

@jcalz
Copy link
Contributor

jcalz commented Oct 9, 2020

Duplicate of #26933 ?

@s0
Copy link
Contributor Author

s0 commented Oct 9, 2020

Duplicate of #26933 ?

Yep, was unable to find it because i had explicitly searched for deferred.

Closing.

@s0 s0 closed this as completed Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants