Skip to content

" 1" with a space is treated like numeric property name #728

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
osdm opened this issue Sep 23, 2014 · 8 comments
Closed

" 1" with a space is treated like numeric property name #728

osdm opened this issue Sep 23, 2014 · 8 comments
Assignees
Labels
Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification

Comments

@osdm
Copy link

osdm commented Sep 23, 2014

Quoted literal property names with leading or trailing spaces are treated as numeric property names, although they are not treated as numbers by JS.

class A {
  [i: number]: number;
  public "1": string = "no space"; // Error here - OK
  public " 1": string = "space"; // Error here - Not expected?
}
var aaa = new A();
window.alert(aaa[1]); // Shows "no space" to confirm JS behaviour
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Sep 23, 2014
@DanielRosenwasser
Copy link
Member

I believe that technically, this isn't a bug, but it may prompt us to review the TypeScript spec. Perhaps @ahejlsberg, @JsonFreeman, or others can clarify.

3.7.4 Index Signatures

A _numerically named property_ is a property whose name is a valid numeric literal. Specifically, a property with a name N for which ToNumber(N) is not NaN, where ToNumber is the abstract operation defined in ECMAScript specification.

@RyanCavanaugh
Copy link
Member

The definition should probably be tightened to only apply to properties x such that ToString(ToNumber(x)) === x. Similarly, names like 1e2 are not actually numerically-named for the purposes of runtime behavior.

@JsonFreeman
Copy link
Contributor

Right, I remember discussing this with @RyanCavanaugh. The ecmaScript rules around this can get pretty weird, as 1e2 would not be the result of a ToString, but 1e25 can be.

@sophiajt sophiajt added this to the TypeScript 2.0 milestone Sep 30, 2014
@ahejlsberg ahejlsberg added the Spec Issues related to the TypeScript language specification label Feb 3, 2015
@DanielRosenwasser
Copy link
Member

Any reason this has the milestone of 2.0? This is a relatively minor spec change.

@JsonFreeman
Copy link
Contributor

Agreed

@mhegazy mhegazy modified the milestones: TypeScript 1.5, TypeScript 1.5.1 Apr 23, 2015
@ghost
Copy link

ghost commented May 22, 2015

@ahejlsberg, @osdm,
this bug is not reproducible in Version 1.5.0-beta (npm install [email protected]), fixed by #860.

@DanielRosenwasser
Copy link
Member

Thanks @jasonwilliams200OK, right now this tracks the need to update the spec.

@mhegazy mhegazy removed the Bug A bug in TypeScript label May 27, 2015
@mhegazy mhegazy modified the milestones: TypeScript 1.5.2, TypeScript 1.6 Jun 17, 2015
@ahejlsberg
Copy link
Member

Fixed in #4033.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 5, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

7 participants