Files
traitify-ts/src/util/extend.ts
Julien Valverdé 8de5750d2e
Some checks failed
continuous-integration/drone/push Build is failing
ExtendPlain -> Extend
2024-02-19 17:50:34 +01:00

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>,
// ]>
// ]>