0.1.0 #1

Merged
Thilawyn merged 65 commits from next into master 2024-02-06 03:15:40 +01:00
6 changed files with 23 additions and 40 deletions
Showing only changes of commit db15ee23ba - Show all commits

View File

@@ -9,7 +9,7 @@ export type AddAbstractToImplClass<
Abstract extends {},
> = (
Class<
InstanceType<ImplClass> & Abstract,
Abstract & InstanceType<ImplClass>,
ConstructorParameters<ImplClass>
> &
StaticMembers<ImplClass>

View File

@@ -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>,
)
}

View File

@@ -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
}

View File

@@ -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"]>
}

View File

@@ -1,4 +1,3 @@
export * from "./class"
export * from "./extend"
export * from "./inheritance"
export * from "./misc"

View File

@@ -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"]>
}