镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

'symbol' is not allowed as an index signature parameter type #7667

Description

@malibuzios

TypeScript Version:

1.8.7 (ES6 mode)

Code

type SymbolKeysGiveNumbers = { [x: symbol]: number };

Expected behavior:
Should work

Actual behavior:
Error: an index signature parameter must be 'string' or 'number'

However:
Code

let x: { [key: string]: any };
x[Symbol("abcd")] = 12;

Expected behavior:
Should not work based on the error above

Actual behavior:
Works

Conclusion
Symbol type should be allowed as an index signature parameter type as in practice it is accepted as a valid index key type. Even the error message when doing something like:

let x: { [key: string]: any };
x[true] = 1;

includes 'symbol' as a valid option:

An index expression argument must be of type 'string', 'number', 'symbol' or 'any'

Activity

  1. mhegazy commented on Mar 24, 2016

    @mhegazy
    Contributor

    duplicate of #1863

  2. mhegazy commented on Mar 24, 2016

    @mhegazy
    Contributor

    image

  3. malibuzios commented on Mar 24, 2016

    @malibuzios
    Author

    Sorry, I was quick to open an issue. I usually search extensively but I was so surprised the feature didn't exist so I assumed there wasn't one.. :)

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

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