DEV Community


Deprecated Decorator

shadowtime2000 profile image shadowtime2000 ・1 min read

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 {

    doSomething() {
        console.log("DO SOMETHING!")
Enter fullscreen mode Exit fullscreen mode


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`);
        return descriptor;
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Editor guide