← All Exercises

Method Decorator Logging

intermediatetypescript~25min

Background

Decorators provide a way to modify class methods and properties declaratively, used in frameworks like NestJS and Angular.

Problem

Write a logging decorator that wraps a class method, printing the method name, arguments, and return value when called.

Input

A class with decorated methods.

Output

The method executes normally with added logging output.

Sample tests

Sample 1

Input: myClass.greet("Alice")
Expected: Logs: greet(Alice) -> Hello Alice

Your solution

Learning objective

Learn decorator implementation, PropertyDescriptor manipulation, and method wrapping.