在 TypeScript 中推断构造函数类型

Mar*_*uch 7 typescript conditional-types

是否可以推断 TypeScript 中类的构造函数类型?我尝试了这个,但似乎不起作用:

type Constructor<K> = K extends { new: infer T } ? T : any;
Run Code Online (Sandbox Code Playgroud)

shu*_*son 1

您可以像这样通过构造函数来引用类类型,而不是尝试推断它吗?

type Constructor<K> = { new(): K };

const x: Constructor<String> = String; 

const s = new x();
Run Code Online (Sandbox Code Playgroud)