Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow pass through of class-properties #12212

Open
@jthomaschewski

Description

@jthomaschewski

TypeScript Version:

  • 2.2.0-dev.20161113 (Not version specific)
  • target = esnext, jsx = preserve

Description
I expect Typescript to more or less only strip types but preserve the rest - based on the target compilerOption. Especially when using a target like es2017 or even esnext.

Class-properties are always moved into the constructor. This prevents hot-reloading of class-property functions when using react-hot-loader 3.

Using them is a common pattern for binding event-handler functions to this without having to do this for every method in the constructor.

Code

class MyClass {
  prop1: number = 123;
  handleClick = () => {
    console.log('Click handled');
  }
  render() {
    return <button onClick={this.handleClick}>Click me</button>;
  }
}

Expected emit:

class MyClass {
  prop1 = 123;
  handleClick = () => {
    console.log('Click handled');
  }
  render() {
    return <button onClick={this.handleClick}>Click me</button>;
  }
}

Actual emit:

class MyClass {
  constructor() {
    super(...arguments);
    this.prop1 = 123;
    this.handleClick = () => {
      console.log('Click handled');
    };
  }
  render() {
    return <button onClick={this.handleClick}>Click me</button>;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptES NextNew featurers for ECMAScript (a.k.a. ESNext)Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions