Skip to content

Incorrect constraint violation error using keyof with generic #12311

Closed
@RyanCavanaugh

Description

@RyanCavanaugh

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'.

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