Skip to content

Support union type as index signature parameter type. #2611

Closed
@saml

Description

@saml

Given:

interface Foo {
  [key: string | number]: boolean;
}

I get

bleh.ts(2,4): error TS1023: An index signature parameter type must be 'string' or 'number'.

A workaround is:

interface Foo {
  [key: number]: boolean;
  [key: string]: boolean;
}

But, I need to match up the type of value, boolean. Since it's a repetition, it could be useful to programmers to specify index signature parameter type as string, number, string | number, or number | string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions