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

Automagic data properties in JavaScript classes #4554

Closed
jrieken opened this issue Aug 31, 2015 · 3 comments
Closed

Automagic data properties in JavaScript classes #4554

jrieken opened this issue Aug 31, 2015 · 3 comments
Assignees
Labels
Duplicate An existing issue was already created

Comments

@jrieken
Copy link
Member

jrieken commented Aug 31, 2015

The ES6 spec for classes doesn't include properties making the code below valid JavaScript (and invalid TypeScript) code

class Cat { 
  constructor(name) {
    this.name = name;
  }

  speak() {
    console.log(this.name + ' makes a noise.');
  }
}

When feeding code like this into the TypeScript compiler you get an error about this.name not being defined. TypeScript should be able to detect that this is a JavaScript class (*.js,*.jsx-files) and (1) not mark the property access this.name as error and (2) offer tooling support for the data property (IntelliSense et al)

@mhegazy mhegazy added Suggestion An idea for TypeScript Bug A bug in TypeScript labels Aug 31, 2015
@mhegazy mhegazy added this to the TypeScript 1.7 milestone Aug 31, 2015
@danquirk
Copy link
Member

danquirk commented Sep 4, 2015

We have another issue somewhere tracking adding support for this style of pattern (ie enumerate assignments to this in the constructor body and consider them instance properties implicitly) but I can't find it at the moment.

@billti
Copy link
Member

billti commented Oct 8, 2015

#4790 covers this and other topics for better TypeScript inference of < ES6 style JavaScript.

@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed Bug A bug in TypeScript Salsa Suggestion An idea for TypeScript labels Oct 8, 2015
@RyanCavanaugh
Copy link
Member

#4955

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants