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

Incorrect constraint violation error using keyof with generic #12311

Closed
RyanCavanaugh opened this issue Nov 16, 2016 · 1 comment
Closed

Incorrect constraint violation error using keyof with generic #12311

RyanCavanaugh opened this issue Nov 16, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@RyanCavanaugh
Copy link
Member

TypeScript Version: master

Code

interface HTMLKind {
    "a": HTMLAnchorElement;
    "div": HTMLDivElement;
    "span": HTMLSpanElement;
    "input": HTMLInputElement;
    // ... dozens more ...
    [s: string]: HTMLElement;
}

// Incorrect error on the return type here
declare function getElementsByTagName<T extends keyof HTMLKind>(k: T): NodeListOf<HTMLKind[T]>;

Expected behavior:
No error

Actual behavior:

Type 'HTMLKind[T]' does not satisfy the constraint 'Node'.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 18, 2016

This is blocking the change to lib.d.ts to reduce symbol instantiations at the moment, see microsoft/TypeScript-DOM-lib-generator#166

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Nov 18, 2016
@ahejlsberg ahejlsberg added this to the TypeScript 2.1.3 milestone Nov 18, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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

3 participants