Extend
All checks were successful
Lint / lint (push) Successful in 12s

This commit is contained in:
Julien Valverdé
2024-07-29 20:32:39 +02:00
parent a07181f758
commit 5690f75cdf
5 changed files with 66 additions and 50 deletions

View File

@@ -1,69 +1,54 @@
import type { CommonKeys2 } from "./CommonKeys"
import type { CommonKeys } from "./CommonKeys"
export type Extend<T extends readonly object[]> = (
export type Extend<Super, Self> =
Extendable<Super, Self> extends true
? Omit<Super, CommonKeys<Self, Super>> & Self
: never
export type Extendable<Super, Self> =
Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? true
: false
export type ExtendAll<T extends readonly object[]> =
T extends readonly [
infer Super,
infer Self,
...infer Rest extends readonly object[],
]
? Pick<Self, CommonKeys2<Self, Super>> extends Pick<Super, CommonKeys2<Self, Super>>
? Extend<readonly [
Omit<Super, CommonKeys2<Self, Super>> & Self,
...Rest,
]>
? Extendable<Super, Self> extends true
? ExtendAll<readonly [Extend<Super, Self>, ...Rest]>
: never
: T extends readonly [infer Self]
? Self
: {}
)
export type Extend2<Self, Super> = Omit<Super, CommonKeys2<Self, Super>> & Self
export type Override<T extends readonly object[]> = (
export type ExtendableAll<T extends readonly object[]> =
T extends readonly [
infer Super,
infer Self,
...infer Rest extends readonly object[],
]
? Override<readonly [
Omit<Super, CommonKeys2<Self, Super>> & Self,
...Rest,
]>
: T extends readonly [infer Self]
? Self
: {}
)
export type Extendable<T extends readonly object[]> = (
T extends readonly [
infer Super,
infer Self,
...infer Rest extends readonly object[],
]
? Pick<Self, CommonKeys2<Self, Super>> extends Pick<Super, CommonKeys2<Self, Super>>
? Extendable<readonly [
Omit<Super, CommonKeys2<Self, Super>> & Self,
...Rest,
]>
? Extendable<Super, Self> extends true
? ExtendableAll<readonly [Extend<Super, Self>, ...Rest]>
: false
: true
)
export type NonExtendableKeys<T extends readonly object[]> = (
T extends readonly [
infer Super extends object,
infer Self extends object,
...infer Rest extends readonly object[],
]
? {[K in keyof Super & keyof Self]: Self[K] extends Super[K]
? never
: K
}[keyof Super & keyof Self]
| NonExtendableKeys<readonly [
Super & Self,
...Rest,
]>
: void
)
// export type NonExtendableKeys<T extends readonly object[]> = (
// T extends readonly [
// infer Super extends object,
// infer Self extends object,
// ...infer Rest extends readonly object[],
// ]
// ? {[K in keyof Super & keyof Self]: Self[K] extends Super[K]
// ? never
// : K
// }[keyof Super & keyof Self]
// | NonExtendableKeys<readonly [
// Super & Self,
// ...Rest,
// ]>
// : void
// )