Extension work
Some checks failed
Lint / lint (push) Failing after 10s

This commit is contained in:
Julien Valverdé
2025-02-21 05:22:19 +01:00
parent 256638bc06
commit 8252b6cbdf
2 changed files with 44 additions and 5 deletions

View File

@@ -1,10 +1,28 @@
import type { Effect } from "effect"
import * as ReffuseContext from "./ReffuseContext.js"
import * as Reffuse from "./Reffuse.js"
import type { Simplify } from "effect/Types"
import type { Merge, StaticType } from "./types.js"
const make = <T extends object>(extension: T) =>
<R extends typeof Reffuse.Reffuse>(base: R) => {
const make = <Ext extends object>(extension: Ext) =>
<
BaseClass extends typeof Reffuse.Reffuse<R>,
R,
>(
base: BaseClass & typeof Reffuse.Reffuse<R>
): (
{ new(): Merge<InstanceType<BaseClass>, Ext> } &
StaticType<BaseClass>
) => {
const class_ = class extends base {}
return class_
}
const cls = make({
prout<R>(this: Reffuse.Reffuse<R>) {}
})(Reffuse.Reffuse)
class Cls extends cls {}
const cls2 = make({
aya() {}
})(cls)

View File

@@ -0,0 +1,21 @@
/**
* Extracts the common keys between two types
*/
export type CommonKeys<A, B> = Extract<keyof A, keyof B>
/**
* Obtain the static members type of a constructor function type
*/
export type StaticType<T extends abstract new (...args: any) => any> = Omit<T, "prototype">
export type Extend<Super, Self> =
Extendable<Super, Self> extends true
? Omit<Super, CommonKeys<Self, Super>> & Self
: never
export type Extendable<Super, Self> =
Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
? true
: false
export type Merge<Super, Self> = Omit<Super, CommonKeys<Self, Super>> & Self