Mar*_*uch 7 typescript conditional-types
是否可以推断 TypeScript 中类的构造函数类型?我尝试了这个,但似乎不起作用:
type Constructor<K> = K extends { new: infer T } ? T : any;
Run Code Online (Sandbox Code Playgroud)
您可以像这样通过构造函数来引用类类型,而不是尝试推断它吗?
type Constructor<K> = { new(): K };
const x: Constructor<String> = String;
const s = new x();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5886 次 |
最近记录: |