This is the start of a series I am creating with various useful Typescript decorators.
You can track the progress of the series on Github.
The Decorator
I want this decorator to be used like this:
class MyClass {
@Deprecated()
doSomething() {
console.log("DO SOMETHING!")
}
}
Source
function Deprecated(): MethodDecorator {
return (target: Object, key: string | symbol, descriptor: PropertyDescriptor) => {
const original = descriptor.value;
descriptor.value = (...args: any) => {
console.warn(`Warning: ${String(key)} is deprecated`);
original(...args);
}
return descriptor;
}
}
Top comments (0)