Open bushmango opened 8 years ago
Upon further testing, it doesn't work when applied to functions either D:
SyntaxError: @autobind can only be used on functions, not: undefined
class AGreatComponent extends React.Component<{},{}> {
@autobind _bound() { logger.x('bound func called') } ...
What version of TypeScript? What compiler flags?
"typescript": "^2.0.2" (RC)
"compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "allowSyntheticDefaultImports": true, "sourceMap": true, "noImplicitAny": false, "removeComments": false, "preserveConstEnums": true, "declaration": true, "pretty": true, "outDir": "./lib/", "experimentalDecorators": true, "noFallthroughCasesInSwitch": true, "forceConsistentCasingInFileNames": true, "pretty": true, "jsx": "react", "baseUrl": "." },
I'm looking forward to movement on this
I use an arrow function instead. Seems to work just fine.
private handleSelection = (record, index, event) => {
this.setState(() => ({ selectedData: record }));
};
@0x80 Arrow function has its own set of problems.
SyntaxError: @autobind can only be used on functions, not: undefined
@autobind class AGreatComponent extends React.Component<{},{}> { ... }
My guess is there's a problem in the class vs function detection algorithm:
https://github.com/jayphelps/core-decorators.js/blob/master/src/autobind.js
function handle(args) { if (args.length === 1) { return autobindClass(...args); } else { return autobindMethod(...args); <-- code is going here instead } }
I'm not sure how to fix it.
I love core-decorators by the way! Made my last project much cleaner. Thanks for your work!