javascript - How do I create a class decorator for mixing new methods into a React component when using Typescript? -
i'm trying create decorator mix new methods react component. i've gotten desired result via following:
function testdecorator(target) { const testmethod = function testmethod() { return 'successfully mixed testmethod component'; }; target.prototype.testmethod = testmethod; } @testdecorator export class testcomponent extends react.component<{}, {}> { // ... render() { console.log('this.testmethod', this.testmethod()); // outputs "successfully mixed testmethod component" } }
this compiles , outputs expected value, produces transpiler error: property 'testmethod' not exist on type 'testcomponent'. there way avoid error? i.e. possible teach typescript values mixed (react component) class via decorator?
right there no way omit error except of removing type checks casting any
or interface have method defined.
here pending request: class decorator mutation
Comments
Post a Comment