有没有办法将联合类型转换为交集类型:
type FunctionUnion = () => void | (p: string) => void
type FunctionIntersection = () => void & (p: string) => void
Run Code Online (Sandbox Code Playgroud)
我想应用转换FunctionUnion来获取FunctionIntersection
我有一个未知类型的联盟。我想得到它的合并类型。例如:
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)