Skip to content

Union types are not allowed in indexers #1715

Closed

Description

@jods4

I have declared function getter(key: string|number).
Inside I try to do var x = someObject[key]
I get a TS error saying "An index expression argument must be of type 'string', 'number' or 'any'.
Obviously key satisfies this constraint as it is either a string or a number. But I guess the TS compiler does hard type equality checks in this case.

Activity

  1. ahejlsberg commented on Jan 18, 2015

    @ahejlsberg
    Member

    You're right, we'll fix that.

  2. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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