如何从构造函数中推断类类型或实例类型?
编辑:我只得到了原型,并且想找回类类型。请参阅装饰器示例。
Class User {}
// The following makes me really sad
User.prototype/* Object */.constructor/* Function */
带有属性装饰器的示例:
// My code
// I cannot get class/instance type from T...
const Prop = <T>({ constructor }: T) => {}
// My user's code
class User {
@Prop
photos
}
谢谢
答案 0 :(得分:0)
尝试InstanceType
:
type UserInstance = InstanceType<User>