TypeScript Class Decorator Basic class decorator


A class decorator is just a function that takes the class as its only argument and returns it after doing something with it:

function log<T>(target: T) {
    // Do something with target
    // Return target
    return target;


We can then apply the class decorator to a class:

class Person {
    private _name: string;
    public constructor(name: string) {
        this._name = name;
    public greet() {
        return this._name;