Extendable
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-02-19 18:23:09 +01:00
parent 394d267d74
commit b9dc68d97b
2 changed files with 25 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ import { TraitClass } from "./Trait"
import { trait } from "./TraitBuilder"
import { Implements, ImplementsStatic, TraitExpressionClass } from "./TraitExpression"
import { expression } from "./TraitExpressionBuilder"
import { Extendable } from "./util"
const PrintsHelloOnNew = trait
@@ -81,3 +82,9 @@ class User extends exp.extends implements Implements<typeof exp> {
}
console.log(new User())
type T = Extendable<[
{ prout: string },
{ prout: "gneugneu" },
]>

View File

@@ -21,18 +21,25 @@ import { CommonKeys } from "."
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
T extends [infer Super, infer Self, ...infer Rest extends object[]]
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? Extend<[
Omit<Super, CommonKeys<Self, Super>> & Self,
...Rest,
]>
: never
: T extends [infer Self]
? Self extends object
? Self
: never
? Self
: {}
)
export type Extendable<T extends readonly object[]> = (
T extends [infer Super, infer Self, ...infer Rest extends object[]]
? Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? Extendable<[
Omit<Super, CommonKeys<Self, Super>> & Self,
...Rest,
]>
: false
: true
)