Created
November 30, 2016 00:12
-
-
Save jsoendermann/a289d46eb3420004674bc61d56220e85 to your computer and use it in GitHub Desktop.
TypeScript decorator that changes method type signature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tsconfig.json: | |
// { | |
// "compilerOptions": { | |
// "target": "es6", | |
// "experimentalDecorators": true | |
// } | |
// } | |
const decorator = (target: any, propertyKey: string, descriptor: PropertyDescriptor) => { | |
const originalMethod = descriptor.value; | |
descriptor.value = (a: number, b: number): number => originalMethod.call(this, a + b); | |
}; | |
class A { | |
@decorator | |
method(n: number): number { | |
return n; | |
} | |
} | |
const a = new A(); | |
a.method(1, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I dont think so