Co-authored-by: Julien Valverdé <julien.valverde@mailo.com> Reviewed-on: https://git.jvalver.de/Thilawyn/traitify-ts/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
25
src/util/extend.ts
Normal file
25
src/util/extend.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Call, ComposeLeft, Fn, Match, Tuples } from "hotscript"
|
||||
import { CommonKeys } from "."
|
||||
|
||||
|
||||
type ExtendReducer<Super, Self> = (
|
||||
Pick<Self, CommonKeys<Self, Super>> extends Pick<Super, CommonKeys<Self, Super>>
|
||||
? Omit<Super, CommonKeys<Self, Super>> & Self
|
||||
: never
|
||||
)
|
||||
interface ExtendReducerFn extends Fn {
|
||||
return: ExtendReducer<this["arg0"], this["arg1"]>
|
||||
}
|
||||
|
||||
export type ExtendFn = Tuples.Reduce<ExtendReducerFn, {}>
|
||||
export type Extend<T extends {}[]> = Call<ExtendFn, T>
|
||||
|
||||
|
||||
export type ExtendableFn = ComposeLeft<[
|
||||
ExtendFn,
|
||||
Match<[
|
||||
Match.With<never, false>,
|
||||
Match.With<any, true>,
|
||||
]>
|
||||
]>
|
||||
export type Extendable<T extends {}[]> = Call<ExtendableFn, T>
|
||||
Reference in New Issue
Block a user