Skip to content

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

Closed
@rkirov

Description

@rkirov

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions