Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index signature parameter should be able to accept types derived from 'string' or 'number' #17528

Closed
garkin opened this issue Jul 31, 2017 · 1 comment

Comments

@garkin
Copy link

garkin commented Jul 31, 2017

TypeScript Version: 2.4.2 / nightly (2.5.0-dev.20170727)

Code

type EntityId = number;
const entityMap: { [id: EntityId]: number | undefined } = {};  // error

enum SomeEnum { A, B, C }
const someEnumMap: { [id: SomeEnum]: number | undefined } = {};  // error

const enum ConstEnum { A, B, C }
const constEnumMap: { [id: ConstEnum]: number | undefined } = {};  // error

Playground

Expected behavior: Succesfull compilation.

Actual behavior: Getting an error:

index.ts(2,21): error TS1023: An index signature parameter type must be 'string' or 'number'.
index.ts(5,23): error TS1023: An index signature parameter type must be 'string' or 'number'.
index.ts(8,24): error TS1023: An index signature parameter type must be 'string' or 'number'.
@kitsonk
Copy link
Contributor

kitsonk commented Jul 31, 2017

Duplicate of #2491
Duplicate of #13042

Search is your friend!

@garkin garkin closed this as completed Jul 31, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants