0.1.0 #1
@@ -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, [
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./class"
|
||||
export * from "./extend"
|
||||
export * from "./inheritance"
|
||||
export * from "./misc"
|
||||
|
||||
7
src/util/misc.ts
Normal file
7
src/util/misc.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Fn } from "hotscript"
|
||||
import { Simplify } from "type-fest"
|
||||
|
||||
|
||||
export interface SimplifyFn extends Fn {
|
||||
return: Simplify<this["arg0"]>
|
||||
}
|
||||
Reference in New Issue
Block a user