对获取实例属性/静态属性的一些看法
来源:8-13 【 TS 泛型类约束】 Vue3源码中的T extends object + extends keyof 【 Vue3源码应用】 1

草莓奶昔cmnx
2021-10-15
获取Order类实例属性
type InstancePropKeys<T extends object, K = keyof T> = K extends any ? K : never
type Bar = InstancePropKeys<Order>
获取Order类静态属性
type StaticPropKeys<Constructor extends abstract new (...args: any[]) => any> = Exclude<
keyof Constructor,
'prototype'
>
type Foo = StaticPropKeys<typeof Order>
写回答
1回答
-
keviny79
2021-10-17
领悟能力不错!
022022-02-03
相似问题