Skip to content

Access object with empty-string key #15209

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

Closed
ikatyang opened this issue Apr 16, 2017 · 2 comments
Closed

Access object with empty-string key #15209

ikatyang opened this issue Apr 16, 2017 · 2 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@ikatyang
Copy link
Contributor

TypeScript Version: 2.3.0-dev.20170415

{
  "compilerOptions": {
    "strict": true
  }
}

Code

declare const x: {
  '': string;
  'a': string;
  'a-b': string;
}

x[''] // error TS7017: Element implicitly has an 'any' type because type '{ '': string; 'a': string; 'a-b': string; }' has no index signature.
x['a'] // fine
x['a-b'] // fine

Expected behavior:
no error

Actual behavior:
error TS7017: Element implicitly has an 'any' type because type '{ '': string; 'a': string; 'a-b': string; }' has no index signature.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 17, 2017
@mhegazy mhegazy added the Help Wanted You can do this label Apr 17, 2017
@mhegazy mhegazy added this to the Community milestone Apr 17, 2017
@HerringtonDarkholme
Copy link
Contributor

May I ask the use case of empty string key? It seems like a strange pattern for me.

@ikatyang
Copy link
Contributor Author

I just find out this bug accidentally, it looks strange to me too.

But it is still a legal case, so I reported it. 😅

vkurchatkin added a commit to vkurchatkin/TypeScript that referenced this issue May 1, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.4, Community May 1, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 1, 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
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants