TS Class Decorator

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2020 Nov 24 5:46
Editor
Edited
Edited
2025 Jun 4 9:46
Refs
Refs
function classDecorator() { return function <T extends {new(...args:any[]):{}}> (constructor:T) { return class extends constructor { newProperty = "new property"; hello = "override"; } } } @classDecorator() class Test { property = "property"; hello: string; constructor(m: string) { this.hello = m; } } let t = new Test("world") console.log(t) Test { property: 'property', hello: 'override', newProperty: 'new property' }
 
<T extends {new(...args:any[]):{}}> - You are basically saying that your class need a constructor in its definition through this (new...)
 

정적 타이핑 확장 안댐

 
 
 
 

Recommendations