40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { CommonKeys } from "."
|
|
|
|
|
|
// type ExtendReducer<Super, Self> = (
|
|
// Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
|
|
// ? Omit<Super, CommonKeys<Self, Super>> & Self
|
|
// : never
|
|
// )
|
|
// interface ExtendReducerFn extends Fn {
|
|
// return: ExtendReducer<this["arg0"], this["arg1"]>
|
|
// }
|
|
// export type ExtendFn = Tuples.Reduce<ExtendReducerFn, {}>
|
|
|
|
|
|
export type Extend<T extends readonly object[]> = (
|
|
T extends [infer Super, infer Self, ...infer Rest]
|
|
? Rest extends object[]
|
|
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
|
|
? Extend<[
|
|
Omit<Super, CommonKeys<Self, Super>> & Self,
|
|
...Rest,
|
|
]>
|
|
: never
|
|
: never
|
|
: T extends [infer Self]
|
|
? Self extends object
|
|
? Self
|
|
: never
|
|
: {}
|
|
)
|
|
|
|
|
|
// export type ExtendableFn = ComposeLeft<[
|
|
// ExtendFn,
|
|
// Match<[
|
|
// Match.With<never, false>,
|
|
// Match.With<any, true>,
|
|
// ]>
|
|
// ]>
|