66
src/Types/Extend.ts
Normal file
66
src/Types/Extend.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import type { CommonKeys } from "./CommonKeys"
|
||||
|
||||
|
||||
export type Extend<T extends readonly object[]> = (
|
||||
T extends readonly [
|
||||
infer Super,
|
||||
infer Self,
|
||||
...infer Rest extends readonly object[],
|
||||
]
|
||||
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
|
||||
? Extend<readonly [
|
||||
Omit<Super, CommonKeys<Self, Super>> & Self,
|
||||
...Rest,
|
||||
]>
|
||||
: never
|
||||
: T extends readonly [infer Self]
|
||||
? Self
|
||||
: {}
|
||||
)
|
||||
|
||||
export type Override<T extends readonly object[]> = (
|
||||
T extends readonly [
|
||||
infer Super,
|
||||
infer Self,
|
||||
...infer Rest extends readonly object[],
|
||||
]
|
||||
? Override<readonly [
|
||||
Omit<Super, CommonKeys<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, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
|
||||
? Extendable<readonly [
|
||||
Omit<Super, CommonKeys<Self, 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
|
||||
)
|
||||
Reference in New Issue
Block a user