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

This commit is contained in:
Julien Valverdé
2024-07-29 19:54:10 +02:00
parent fc33429b93
commit a07181f758
2 changed files with 10 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
/**
* Extracts the common keys between two types
*/
export type CommonKeys<A, B> = Extract<keyof A, keyof B>
export type CommonKeys2<A, B> = Extract<keyof A, keyof B>

View File

@@ -1,4 +1,4 @@
import type { CommonKeys } from "./CommonKeys"
import type { CommonKeys2 } from "./CommonKeys"
export type Extend<T extends readonly object[]> = (
@@ -7,9 +7,9 @@ export type Extend<T extends readonly object[]> = (
infer Self,
...infer Rest extends readonly object[],
]
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? Pick<Self, CommonKeys2<Self, Super>> extends Pick<Super, CommonKeys2<Self, Super>>
? Extend<readonly [
Omit<Super, CommonKeys<Self, Super>> & Self,
Omit<Super, CommonKeys2<Self, Super>> & Self,
...Rest,
]>
: never
@@ -18,6 +18,9 @@ export type Extend<T extends readonly object[]> = (
: {}
)
export type Extend2<Self, Super> = Omit<Super, CommonKeys2<Self, Super>> & Self
export type Override<T extends readonly object[]> = (
T extends readonly [
infer Super,
@@ -25,7 +28,7 @@ export type Override<T extends readonly object[]> = (
...infer Rest extends readonly object[],
]
? Override<readonly [
Omit<Super, CommonKeys<Self, Super>> & Self,
Omit<Super, CommonKeys2<Self, Super>> & Self,
...Rest,
]>
: T extends readonly [infer Self]
@@ -39,9 +42,9 @@ export type Extendable<T extends readonly object[]> = (
infer Self,
...infer Rest extends readonly object[],
]
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? Pick<Self, CommonKeys2<Self, Super>> extends Pick<Super, CommonKeys2<Self, Super>>
? Extendable<readonly [
Omit<Super, CommonKeys<Self, Super>> & Self,
Omit<Super, CommonKeys2<Self, Super>> & Self,
...Rest,
]>
: false