Skip to content

Indexable types don't accept type aliases #18992

Closed
@kujon

Description

@kujon

TypeScript Version: 2.4.2

Is there any reason for the following code failing to compile? As far as I'm aware, type aliases are resolved by TS quite early, so shouldn't the same be true in this case?

Code

type A = string;
type B = number;

type AIndexedNoAlias = {
    [index: string]: any;
};

type AIndexedAlias = {
    // An index signature parameter type must be 'string' or 'number'.
    [index: A]: any;
};

type BIndexedNoAlias = {
    [index: number]: any;
};

type BIndexedAlias = {
    // An index signature parameter type must be 'string' or 'number'.
    [index: B]: any;
};

Expected behavior:
The code above compiles

Actual behavior:
The code above fails to compile, with the following error: An index signature parameter type must be 'string' or 'number'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions