Skip to content

T[K] not assignable even when it's 'any' #23940

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
ghost opened this issue May 7, 2018 · 0 comments
Closed

T[K] not assignable even when it's 'any' #23940

ghost opened this issue May 7, 2018 · 0 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented May 7, 2018

TypeScript Version: 2.9.0-dev.20180430

Code

interface I {
    x: any;
}
type Foo<T extends number> = T;
declare function f<K extends keyof I>(type: K): Foo<I[K]>;

Expected behavior:

No error.

Actual behavior:

src/a.ts:5:53 - error TS2344: Type 'I[K]' does not satisfy the constraint 'number'.

5 declare function f<K extends keyof I>(type: K): Foo<I[K]>;

This was broken by #23768 (fc2f16c): tested that it worked in the commit before it, 4e401ca .

Discovered in ember-data on DefinitelyTyped.

@ghost ghost added the Bug A bug in TypeScript label May 7, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone May 7, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label May 8, 2018
@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

No branches or pull requests

2 participants