將聯合類型轉換為交叉類型是否有方法將聯合類型轉換為交叉類型:type FunctionUnion = () => void | (p: string) => voidtype FunctionIntersection = () => void & (p: string) => void我想將轉換應用到FunctionUnion得到FunctionIntersection
3 回答
德瑪西亞99
TA貢獻1770條經驗 獲得超3個贊
9
type Idx<T extends any, K extends keyof any, Yes> = T extends Record<K, any> ? T[K] & Yes : unknown type ArrayToIntersection<T extends any[]> = Idx<T, '0', Idx<T, '1', Idx<T, '2', Idx<T, '3', Idx<T, '4', Idx<T, '5', Idx<T, '6', Idx<T, '7', Idx<T, '8', Idx<T, '9', unknown>>>>>>>>>>// Usage: => 1 & 2 & 3 & 4type Result = ArrayToIntersection<[1, 2, 3, 4]>
牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
type Param<T> = T extends (arg: infer U) => void ? U : never; type InferredParams = Param<((a: string) => void) | ((a: number) => void)>;string & numberstring | number
添加回答
舉報
0/150
提交
取消
