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;
    }
}
Back | DEV.to

shadowtime2000

If you are looking at this you probably wonder who I am; teenage open source maintainer

shadowtime2000's DEV profile image