← All Exercises

Method Decorators

advancedtypescript~30min

Background

Decorators enable cross-cutting concerns like logging, validation, and caching in class methods.

Problem

Create a method decorator that logs function calls with arguments and return values.

Input

Class method with decorator

Output

Method with added behavior

Sample tests

Sample 1

Input: @log method call
Expected: logged output

Your solution

Learning objective

Learn metaprogramming and aspect-oriented programming