Skip to content

Automagic data properties in JavaScript classes #4554

Closed
@jrieken

Description

@jrieken

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)

Metadata

Metadata

Assignees

Labels

DuplicateAn existing issue was already created

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions