Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

autobind not working with async function #98

Open
JuoCode opened this issue Feb 17, 2017 · 9 comments
Open

autobind not working with async function #98

JuoCode opened this issue Feb 17, 2017 · 9 comments

Comments

@JuoCode
Copy link

JuoCode commented Feb 17, 2017

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
@jayphelps
Copy link
Owner

What compiler are you using?

@JuoCode
Copy link
Author

JuoCode commented Feb 18, 2017

Use tsc, and compile to target es6

@jayphelps
Copy link
Owner

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.

@JuoCode
Copy link
Author

JuoCode commented Feb 20, 2017

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

@damianobarbati
Copy link

any news on this?

@jayphelps
Copy link
Owner

@damianobarbati No updates from me, but others are welcome to dig in and find the cause. 🤕

@dantman
Copy link

dantman commented May 17, 2017

I use this pattern all the time in React Native (babel + browserify) so this error is definitely related to some interaction with TypeScript compiler.

@davidsu
Copy link

davidsu commented Jul 19, 2017

for me it works when running tests ( mocha + node + babel ) but fails on the browser ( webpack + babel )

@BurtHarris
Copy link
Collaborator

BurtHarris commented Aug 4, 2017

Could someone contribute a unit test for this? I'd like to include it in the typescript conversion effort. SEE PR #133.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants