This commit is contained in:
@@ -9,7 +9,7 @@ export type AddAbstractToImplClass<
|
||||
Abstract extends {},
|
||||
> = (
|
||||
Class<
|
||||
InstanceType<ImplClass> & Abstract,
|
||||
Abstract & InstanceType<ImplClass>,
|
||||
ConstructorParameters<ImplClass>
|
||||
> &
|
||||
StaticMembers<ImplClass>
|
||||
|
||||
@@ -4,11 +4,11 @@ import { AbstractTag, RemoveAbstractFromImplClass, Trait, TraitApplierSuperTag }
|
||||
import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util"
|
||||
|
||||
|
||||
type RemoveSupertraitsAbstractFromAbstract<Left, Right> = {
|
||||
[Key in Extract<keyof Left, keyof Right>]: Left[Key]
|
||||
} & {
|
||||
[Key in Exclude<keyof Left, keyof Right>]: Left[Key]
|
||||
}
|
||||
// type RemoveSupertraitsAbstractFromAbstract<Left, Right> = {
|
||||
// [Key in Extract<keyof Left, keyof Right>]: Left[Key]
|
||||
// } & {
|
||||
// [Key in Exclude<keyof Left, keyof Right>]: Left[Key]
|
||||
// }
|
||||
|
||||
|
||||
export class TraitExpression<
|
||||
@@ -61,7 +61,8 @@ export class TraitExpression<
|
||||
) {
|
||||
return new Trait(
|
||||
this,
|
||||
{} as RemoveSupertraitsAbstractFromAbstract<SubtraitAbstract, Implements<typeof this>>,
|
||||
// {} as RemoveSupertraitsAbstractFromAbstract<SubtraitAbstract, Implements<typeof this>>,
|
||||
{} as SubtraitAbstract, // TODO: find a way to cleanly substract Implements<typeof this> from this.
|
||||
apply as any as (Super: AbstractClass<{}>) => RemoveAbstractFromImplClass<SubtraitImplClassWithAbstract, SubtraitAbstract>,
|
||||
)
|
||||
}
|
||||
|
||||
15
src/tests.ts
15
src/tests.ts
@@ -63,25 +63,16 @@ const exp = expression
|
||||
PrintsHelloOnNew,
|
||||
Identifiable<bigint>(),
|
||||
// Identifiable<number>(),
|
||||
StatefulSubscription,
|
||||
ActiveStatefulSubscription,
|
||||
)
|
||||
.build()
|
||||
|
||||
type Abs = Implements<typeof exp>
|
||||
|
||||
// exp.subtrait(
|
||||
// s => {
|
||||
// interface Subtrait extends (typeof s) {
|
||||
|
||||
// }
|
||||
|
||||
// return abstract<Subtrait>()
|
||||
// },
|
||||
// )
|
||||
|
||||
class User extends exp.extends implements Implements<typeof exp> {
|
||||
readonly isStatefulSubscription: true = true
|
||||
declare status: { _tag: "awaitingPayment" } | { _tag: "active"; activeSince: Date; expiresAt?: Date | undefined } | { _tag: "expired"; expiredSince: Date }
|
||||
readonly isActiveStatefulSubscription: true = true
|
||||
declare status: { _tag: "active"; activeSince: Date; expiresAt?: Date | undefined }
|
||||
id: bigint = -1n
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Fn } from "hotscript"
|
||||
import { AbstractClass } from "type-fest"
|
||||
|
||||
|
||||
/**
|
||||
* Represents the static members of a class.
|
||||
* @template Class - A class extending AbstractClass.
|
||||
*/
|
||||
export type StaticMembers<Class extends AbstractClass<any>> = (
|
||||
Omit<Class, "prototype">
|
||||
)
|
||||
|
||||
export interface StaticMembersFn extends Fn {
|
||||
return: StaticMembers<this["arg0"]>
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from "./class"
|
||||
export * from "./extend"
|
||||
export * from "./inheritance"
|
||||
export * from "./misc"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Fn } from "hotscript"
|
||||
import { Simplify } from "type-fest"
|
||||
import { AbstractClass, Simplify } from "type-fest"
|
||||
|
||||
|
||||
/**
|
||||
@@ -9,10 +9,17 @@ import { Simplify } from "type-fest"
|
||||
*/
|
||||
export type CommonKeys<A, B> = Extract<keyof A, keyof B>
|
||||
|
||||
export type KeysOnlyInLeft<Left, Right> = {
|
||||
[K in Exclude<keyof Left, keyof Right>]: Left[K]
|
||||
}
|
||||
|
||||
export interface SimplifyFn extends Fn {
|
||||
return: Simplify<this["arg0"]>
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the static members of a class.
|
||||
* @template Class - A class extending AbstractClass.
|
||||
*/
|
||||
export type StaticMembers<Class extends AbstractClass<any>> = (
|
||||
Omit<Class, "prototype">
|
||||
)
|
||||
export interface StaticMembersFn extends Fn {
|
||||
return: StaticMembers<this["arg0"]>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user