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

String type matching on index signature #4588

Closed
fongandrew opened this issue Sep 1, 2015 · 1 comment
Closed

String type matching on index signature #4588

fongandrew opened this issue Sep 1, 2015 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@fongandrew
Copy link

As of the latest nightly build (8/31/2015), the following code compiles:

interface Bob { [key: string]: any; }
var x: Bob = "something";

With TSC 1.5.3, I got the error message Index signature is missing in type 'String'. Can someone clarify if this is intended behavior? It seems like it might be (#4074), but it also seems a bit weird to be able to assign a string to what is probably intended to be a basic hash map.

@ahejlsberg
Copy link
Member

This is the intended behavior of #4074, the rationale being that any type meets the intended constraint (which basically is none). However, I agree we should probably consider disallowing primitive types since you can't actually add properties to those.

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Sep 1, 2015
@ahejlsberg ahejlsberg added this to the TypeScript 1.7 milestone Sep 1, 2015
@ahejlsberg ahejlsberg self-assigned this Sep 1, 2015
@mhegazy mhegazy modified the milestones: TypeScript 2.0, TypeScript 1.7 Oct 6, 2015
@mhegazy mhegazy assigned sandersn and unassigned ahejlsberg Oct 6, 2015
@RyanCavanaugh RyanCavanaugh added the Fixed A PR has been merged for this issue label Oct 19, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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
Projects
None yet
Development

No branches or pull requests

5 participants