Skip to content

General indexer type #2049

Closed
Closed
@NN---

Description

@NN---

It is impossible to write generic type that represents key-value dictionary:

interface KeyValue<Key, Value> {
    [key: Key]: Value;
}

Key must be string or number, but generic constraints doesn't allow this.

interface KeyValue<Key extends string|number, Value> {
    [key: Key]: Value; // Still error
}

There is 'extends' but there is no 'is' to match exact type.
Something like "Key is string|number" or "Key: string|number" .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions