참고

상속

믹스인

간단 예제

type Constructor<T = {}> = new (...args: any[]) => T;

function Timestamped<TBase extends Constructor>(Base: TBase) {
    return class extends Base {
        timestamp = Date.now();
        PrintTimestamp = () => {
            console.log(`Timestamp : ${new Date(this.timestamp).toISOString()}`);
        }
    };
}

class User {
    public name = '';
}

const TimestampedUser = Timestamped(User);
const instance = new TimestampedUser();

console.log(instance.timestamp);
instance.PrintTimestamp();