ValueOf
This commit is contained in:
9
src/ts/type.ts
Normal file
9
src/ts/type.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// ValueOf 将对象类型转换成值的枚举值
|
||||||
|
// keyof 操作符,遍历对象的key
|
||||||
|
export type ValueOf<T> = T[keyof T];
|
||||||
|
export const enum1 = {
|
||||||
|
AAA: "aaa",
|
||||||
|
BBB: "bbb",
|
||||||
|
} as const;
|
||||||
|
// typeof 提取类型
|
||||||
|
export type TEnum1 = ValueOf<typeof enum1>;
|
Reference in New Issue
Block a user