[英]Is it possible to map the property names of a type into a array type?
Given the following type给定以下类型
type A = {
foo: string
bar: number
}
is it possible to create a mapped/conditional type such that是否可以创建映射/条件类型,以便
type APropertyNameList = MapToProperyNameList<A>
let l1: APropertyNameList = ["foo", "bar] //correct
let l2: APropertyNameList = ["foo", "boom"] //compile error
let l3: APropertyNameList = ["foo", "bar", "bar"] //compile error 2x bar
type A = {
foo: string
bar: number
}
type MyKeys<T> = (keyof T)[];
const l1: MyKeys<A> = ['foo', 'bar'] // Correct
const l2: MyKeys<A> = ['foo', 'boom'] // Error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.