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

Bug from #23592 - Type 'keyof U & K' does not satisfy the constraint 'string | number | symbol' #23648

Closed
kpdonn opened this issue Apr 24, 2018 · 4 comments · Fixed by #23672
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@kpdonn
Copy link
Contributor

kpdonn commented Apr 24, 2018

TypeScript Version: 2.9.0-dev.20180424

Search Terms:
keyof, intersection, conditional types

Code

type Example<T, U> = { [K in keyof T]: K extends keyof U ? UnexpectedError<K> : NoErrorHere<K> }

type UnexpectedError<T extends PropertyKey> = T
type NoErrorHere<T extends PropertyKey> = T

Expected behavior:
No errors.

Actual behavior:
Error on K in UnexpectedError<K> with message

Type 'keyof U & K' does not satisfy the constraint 'string | number | symbol'.
  Type 'keyof U & K' is not assignable to type 'symbol'.

Playground Link:
Link (no error in playground)

Related Issues:
#23592

@ahejlsberg
Copy link
Member

The issue here is that we don't lift constraints over intersection types. Here's a simpler repro:

function foo<T extends string | number, U extends string | number>(x: T & U) {
    let y: string | number = x;  // Error, but shouldn't be
}

We need to lift the individual constraints of T and U such that the intersection type T & U appears to have the constraint string | number (formed by intersecting the individual constraints of T and U).

@ahejlsberg
Copy link
Member

The reason this shows up with #23592 is that we now have union type constraints for keyof T.

@ahejlsberg ahejlsberg self-assigned this Apr 24, 2018
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Apr 24, 2018
@ahejlsberg ahejlsberg added this to the TypeScript 2.9 milestone Apr 24, 2018
@ahejlsberg
Copy link
Member

@mhegazy Do you recall if we already have an issue for this?

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Apr 24, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 25, 2018

@mhegazy Do you recall if we already have an issue for this?

do not think i have seen this one before.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants