【发布时间】:2020-08-12 01:30:23
【问题描述】:
我有一些接口/对象
interface Example1 {
1: object,
2: string,
s: string,
ss: string,
as: string[],
b: boolean,
n: number
}
有一种方法可以只获取具有 T 类型值的字符串类型的键吗?
预期结果:
type ExtractKeysOfValueType<T extends object,K> = ... // do the magic,
ExtractKeysOfValueType<Example1,string> // 's' | 'ss'
我已经使用“提取”来获取字符串类型的键,不包括符号和数字,但我不知道如何继续我的需要
【问题讨论】:
标签: javascript typescript generics typescript-generics