core-decorators
core-decorators copied to clipboard
autobind not working with async function
Use ES7 async function
@autobind
async handleSubmit() {
this.setState({ loggedIn: true })
}
render() {
return (
<button onClick={this.handleSubmit}>Submit</button>
)
}
Error message
Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined
What compiler are you using?
Use tsc
, and compile to target es6
What version of TypeScript? I need as much information as you can give me to help. Also keep in mind that core-decorators does not officially support TypeScript--there are known issues with it.
Typescript: 2.2.0-dev.20170120
core-decorators: 0.15.0
Node: 7.2.0
...core-decorators does not officially support TypeScript...
Working fine in general functions
any news on this?
@damianobarbati No updates from me, but others are welcome to dig in and find the cause. 🤕
I use this pattern all the time in React Native (babel + browserify) so this error is definitely related to some interaction with TypeScript compiler.
for me it works when running tests ( mocha + node + babel ) but fails on the browser ( webpack + babel )
Could someone contribute a unit test for this? I'd like to include it in the typescript conversion effort. SEE PR #133.