打字稿:将对象 属性 类型转换为元组
Typescript: convert object property types to tuple
我正在尝试将任何类型 T
的 属性 类型按顺序转换为包含 T
类型的元组。
type A = {
a: string
b: number
c: string
}
type ToArray<T> = [...{[K in keyof T]: T[K]}[keyof T]] // doesn't work...
type ExpectedResult = [string, number, string]
我尝试使用展开运算符,但无法正常工作。
这已在以下. Please be warned that doing this is not the best idea, and the reasons why are listed in this 中介绍。
将其返回给您的 use-case,您将使用第一个答案中的代码如下:
type A = {
a: string
b: number
c: string
}
type ExpectedResult = ObjValueTuple<A>
游乐场link.
我正在尝试将任何类型 T
的 属性 类型按顺序转换为包含 T
类型的元组。
type A = {
a: string
b: number
c: string
}
type ToArray<T> = [...{[K in keyof T]: T[K]}[keyof T]] // doesn't work...
type ExpectedResult = [string, number, string]
我尝试使用展开运算符,但无法正常工作。
这已在以下
将其返回给您的 use-case,您将使用第一个答案中的代码如下:
type A = {
a: string
b: number
c: string
}
type ExpectedResult = ObjValueTuple<A>
游乐场link.