type KeyOfByType<T extends object, P> = ???type T1 = {
a: string
b: number
c: string
d: object
}type T2 = KeyOfByType<T1, string>// type T2 = "a" | "c"如何定义以上的KeyOfByType?
2 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
type NoneStringKeys<T, K> = { [P in keyof T]: T[P] extends K ? never :P; }[keyof T]type KeyOfByType<T, K> = Pick<T, Exclude<keyof T, NoneStringKeys<T, K>>interface T1 { a: string b: number c: string d: object }type T2 = KeyOfByType<T1, string>
添加回答
举报
0/150
提交
取消