0.1.11 #14
@@ -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)
|
||||
|
||||
21
packages/reffuse/src/types.ts
Normal file
21
packages/reffuse/src/types.ts
Normal 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
|
||||
Reference in New Issue
Block a user