Challenge: Three Biggest Features in TypeScript 5.0

Test your understanding of the three biggest features discussed in this chapter.

We'll cover the following

Task

Implement a decorator function called deprecated that can be applied to methods within a class. This decorator should log a message to the console whenever the decorated method is called. The message should indicate that the method is deprecated. Inside this implementation:

  • Retrieve the name of the method being decorated. Use the context object for this purpose.

  • Define a replacementMethod() to be used in place of the original method. Inside this method, log the warning message using the console.log() method. The warning method should include the method name in it. The warning text should be “Warning: <method_name> is deprecated.” e.g., Warning: 'getValue' is deprecated.

  • Return the replacementMethod.

Playground

Implement your solution in the following playground:

Get hands-on with 1400+ tech skills courses.