ts keys类型枚举

// 从 DataView 类型中取出key
type get_set = keyof Omit<DataView, "buffer" | "byteLength" | "byteOffset">;
type FilterNotStartingWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? never : Set
// 从get_set 中取出以 set字符串开始的成员
type set = FilterNotStartingWith<get_set, "get">
type set2 = Exclude<get_set, `get${string}`>
type set3 = Extract<get_set, `set${string}`>
// 从get_set 中取出以 get字符串开始的成员
type get = FilterNotStartingWith<get_set, "set">
type get2 = Exclude<get_set, `set${string}`>
type get3 = Extract<get_set, `get${string}`>

还有种简单的办法

// type setkeys = "setFloat32" | "setFloat64" | "setInt8" | "setInt16" | "setInt32" | "setUint8" | "setUint16" | "setUint32" | "setBigInt64" | "setBigUint64"
type setkeys = Extract<keyof DataView, `set${string}`>;
// type getkeys = "getFloat32" | "getFloat64" | "getInt8" | "getInt16" | "getInt32" | "getUint8" | "getUint16" | "getUint32" | "getBigInt64" | "getBigUint64"
type getkeys = Extract<keyof DataView, `get${string}`>;
posted @   Ajanuw  阅读(322)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
历史上的今天:
2018-11-14 apollo-server 返回模拟数据
2018-11-14 express+apollo+mongodb
点击右上角即可分享
微信分享提示