Skip to content

Instantly share code, notes, and snippets.

@jsoendermann
Created November 30, 2016 00:12
Show Gist options
  • Save jsoendermann/a289d46eb3420004674bc61d56220e85 to your computer and use it in GitHub Desktop.
Save jsoendermann/a289d46eb3420004674bc61d56220e85 to your computer and use it in GitHub Desktop.
TypeScript decorator that changes method type signature
// 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);
@victorgarciaesgi
Copy link

Is it really working?

@aszmyd
Copy link

aszmyd commented Jan 8, 2019

I dont think so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment