We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// your answers // 把前面几位的代码翻看了几十遍后模仿着写了一边 // Merze { } & { } => {...} // UnionToIntersection { } | { } => { } & { } // DistObj { ... , ... } => { _temp:{} } | { _temp:{} } => { _temp:{} } & { _temp:{} } => {} & {} // ---------------------------------------------------------------------------- type Merze<T> = T extends Function ? T : { [K in keyof T]: T[K] }; // ---------------------------------------------------------------------------- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; // ---------------------------------------------------------------------------- type ValueExt<K, V> = V extends V ? { [_ in K & string]: V } : never // ---------------------------------------------------------------------------- type DistObj<T, K extends keyof T = keyof T> = Merze< UnionToIntersection< K extends K ? { _temp: ValueExt<K, DistributeUnions<T[K]>> } : never > extends { _temp: infer O } ? O : {}> // ---------------------------------------------------------------------------- type ArrExt<A extends any[], U> = A extends A ? U extends U ? [U, ...A] : never : never // ---------------------------------------------------------------------------- type DistArr<T> = T extends [infer U, ... infer L] ? ArrExt<DistArr<L>, DistributeUnions<U>> : [] // ---------------------------------------------------------------------------- type DistributeUnions<T> = T extends readonly any[] ? DistArr<T> : T extends Function ? T // 这个似乎还得完善一下。。。 : T extends { [_: string]: any } ? DistObj<T> : T // ----------------------------------------------------------------------------
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: