Open
Description
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>;
}
}