Skip to content

Inference of the Enum object as a Record fails in TS3.3.3333 #30218

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

Closed
rkirov opened this issue Mar 5, 2019 · 2 comments · Fixed by #30944
Closed

Inference of the Enum object as a Record fails in TS3.3.3333 #30218

rkirov opened this issue Mar 5, 2019 · 2 comments · Fixed by #30944
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@rkirov
Copy link
Contributor

rkirov commented Mar 5, 2019

TypeScript Version: 3.4.0-dev.201xxxxx and 3.3.3333

Search Terms: enum, record

Code

declare function enumValues<K extends string, V extends string>(
    e: Record<K, V>): V[];

enum E {
  A = 'foo',
  B = 'bar'
}

let x:E[] = enumValues(E);

Expected behavior:
No type error, because K is inferred to be 'A' | 'B' and V is inferred to be 'foo' | 'bar'.

Actual behavior:
Type error after TS 3.3:

error TS2322: Type 'string[]' is not assignable to type 'E[]'.

It appears that K and V are chosen to be the lower bound string.

@RyanCavanaugh
Copy link
Member

@ahejlsberg intended? Would like to understand before we publish the RC

@ahejlsberg ahejlsberg added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Apr 15, 2019
@ahejlsberg
Copy link
Member

I agree, should resolve to E[] and not string[].

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Apr 15, 2019
@ahejlsberg ahejlsberg added this to the TypeScript 3.5.0 milestone Apr 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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