相关疑难解决方法(0)

将联合类型转换为交集类型

有没有办法将联合类型转换为交集类型:

type FunctionUnion = () => void | (p: string) => void
type FunctionIntersection = () => void & (p: string) => void
Run Code Online (Sandbox Code Playgroud)

我想应用转换FunctionUnion来获取FunctionIntersection

typescript

55
推荐指数
4
解决办法
4645
查看次数

Typescript:从联合类型获取合并/组合类型

我有一个未知类型的联盟。我想得到它的合并类型。例如:

const a = {
    x: 10
}
const b = {
    y: 'qwer'
}

const array = [a, b]

type TArr = typeof array
// I use a function which receives an array as argument so I only have type of array from now on

type TUnion = keyof TArr[number] // { x: number } | { y: string }
type TMerge = ? // { x: number } & { y: string }
Run Code Online (Sandbox Code Playgroud)

哪里TMerge几乎相同

type TMerge …
Run Code Online (Sandbox Code Playgroud)

arrays union merge types typescript

5
推荐指数
0
解决办法
3074
查看次数

标签 统计

typescript ×2

arrays ×1

merge ×1

types ×1

union ×1