8000 The generics don't work with the type of a key value object · Issue #16957 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
The generics don't work with the type of a key value object #16957
@zabirauf

Description

@zabirauf

TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)

Code

// A *self-contained* demonstration of the problem follows...
function test<T extends string | number>(a: T): {[key: T]: boolean} {
    const map: { [key: T]: boolean } = {};
    return map;
}

Expected behavior:
The type system should not complain that the key type of map should be string or number.

Actual behavior:
It gives error that the key of map should be string or number even though T is string or number

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0