0.1.0 #1

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

View File

@@ -1,7 +1,7 @@
import { Call, Fn, Pipe, Tuples } from "hotscript"
import { AbstractClass, Opaque, Simplify } from "type-fest"
import { Trait, TraitAbstractMembersFn, TraitApplierSuperTag, TraitImplInstanceFn } from "."
import { ExtendFn } from "./util"
import { Call, Pipe, Tuples } from "hotscript"
import { AbstractClass, Opaque } from "type-fest"
import { Trait, TraitAbstractMembersFn, TraitApplierSuperTag, TraitImplClassFn, TraitImplInstanceFn } from "."
import { ExtendFn, SimplifyFn, StaticMembersFn } from "./util"
class TraitsExpression<
@@ -15,26 +15,34 @@ class TraitsExpression<
extends(): (
AbstractClass<
Call<ExtendFn, [
Pipe<[
InstanceType<Super>,
...Call<Tuples.Map<TraitImplInstanceFn>, Traits>,
], [
ExtendFn,
SimplifyFn,
]>,
ConstructorParameters<Super>
>
> &
Pipe<[
Super,
...Call<Tuples.Map<TraitImplClassFn>, Traits>,
], [
Tuples.Map<StaticMembersFn>,
ExtendFn,
SimplifyFn,
]>
) {
return this.traits.reduce(
(previous, trait) => trait.apply(previous),
this.superclass as Opaque<Super, TraitApplierSuperTag>,
)
) as any
}
}
interface SimplifyFn extends Fn {
return: Simplify<this["arg0"]>
}
export type Implements<Exp extends TraitsExpression<any, any>> = (
Exp extends TraitsExpression<any, infer Traits>
? Pipe<Traits, [

View File

@@ -48,6 +48,8 @@ const exp = expresses(
)
type Impl = Implements<typeof exp>
class User implements Implements<typeof exp> {
class User extends exp.extends() implements Implements<typeof exp> {
id: bigint = -1n
}
new User().id

View File

@@ -1,3 +1,4 @@
import { Fn } from "hotscript"
import { AbstractClass } from "type-fest"
@@ -37,6 +38,10 @@ export type StaticMembers<Class extends AbstractClass<any>> = (
Omit<Class, "prototype">
)
export interface StaticMembersFn extends Fn {
return: StaticMembers<this["arg0"]>
}
/**
* Represents an array of static members corresponding to the provided classes.
* @template Classes - An array of classes extending AbstractClass.

View File

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

7
src/util/misc.ts Normal file
View File

@@ -0,0 +1,7 @@
import { Fn } from "hotscript"
import { Simplify } from "type-fest"
export interface SimplifyFn extends Fn {
return: Simplify<this["arg0"]>
}