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

This commit is contained in:
Julien Valverdé
2024-02-17 17:12:46 +01:00
parent 2fa71aaf37
commit 04146f6c69
2 changed files with 38 additions and 11 deletions

View File

@@ -2,7 +2,30 @@ import { Fn, Pipe, Tuples } from "hotscript"
import { AbstractClass, Class } from "type-fest"
import { Trait } from "./Trait"
import { TraitBuilder } from "./TraitBuilder"
import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util"
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembersFn } from "./util"
type SubtraitAbstract<Exp> = (
ExtendPlain<
MapTraitsToOwnAbstract<
TraitExpression.Traits<Exp>
>
>
)
type MapTraitsToOwnAbstract<T extends readonly any[]> = {
[K in keyof T]: Trait.OwnAbstract<T[K]>
}
type SubtraitStaticAbstract<Exp> = (
ExtendPlain<
MapTraitsToOwnStaticAbstract<
TraitExpression.Traits<Exp>
>
>
)
type MapTraitsToOwnStaticAbstract<T extends readonly any[]> = {
[K in keyof T]: Trait.OwnStaticAbstract<T[K]>
}
export class TraitExpression<
@@ -49,8 +72,8 @@ export class TraitExpression<
) {
return new TraitBuilder(
this,
{},
{},
{} as SubtraitAbstract<This>,
{} as SubtraitStaticAbstract<This>,
Super => class extends Super {},
)
}

View File

@@ -15,17 +15,21 @@ export type ExtendFn = Tuples.Reduce<ExtendReducerFn, {}>
export type Extend<T extends readonly object[]> = Call<ExtendFn, T>
export type ExtendPlain<T extends readonly any[]> = (
export type ExtendPlain<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>>
? ExtendPlain<[
Omit<Super, CommonKeys<Self, Super>> & Self,
...Rest,
]>
: never
: never
: T extends [infer Self]
? Self extends object
? Self
: void
: never
: {}
)