This commit is contained in:
@@ -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 {},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
: {}
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user