0.1.8 (#9)
All checks were successful
Publish / publish (push) Successful in 14s
Lint / lint (push) Successful in 11s

Co-authored-by: Julien Valverdé <julien.valverde@mailo.com>
Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
Julien Valverdé
2024-07-29 20:35:42 +02:00
parent 4366f2af6e
commit 94f16a3967
6 changed files with 91 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@thilawyn/thilalib", "name": "@thilawyn/thilalib",
"version": "0.1.7", "version": "0.1.8",
"type": "module", "type": "module",
"files": [ "files": [
"./dist" "./dist"

4
src/Types/CommonKeys.ts Normal file
View File

@@ -0,0 +1,4 @@
/**
* Extracts the common keys between two types
*/
export type CommonKeys<A, B> = Extract<keyof A, keyof B>

54
src/Types/Extend.ts Normal file
View File

@@ -0,0 +1,54 @@
import type { CommonKeys } from "./CommonKeys"
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 ExtendAll<T extends readonly object[]> =
T extends readonly [
infer Super,
infer Self,
...infer Rest extends readonly object[],
]
? Extendable<Super, Self> extends true
? ExtendAll<readonly [Extend<Super, Self>, ...Rest]>
: never
: T extends readonly [infer Self]
? Self
: {}
export type ExtendableAll<T extends readonly object[]> =
T extends readonly [
infer Super,
infer Self,
...infer Rest extends readonly object[],
]
? Extendable<Super, Self> extends true
? ExtendableAll<readonly [Extend<Super, Self>, ...Rest]>
: false
: true
// export type NonExtendableKeys<T extends readonly object[]> = (
// T extends readonly [
// infer Super extends object,
// infer Self extends object,
// ...infer Rest extends readonly object[],
// ]
// ? {[K in keyof Super & keyof Self]: Self[K] extends Super[K]
// ? never
// : K
// }[keyof Super & keyof Self]
// | NonExtendableKeys<readonly [
// Super & Self,
// ...Rest,
// ]>
// : void
// )

15
src/Types/Merge.ts Normal file
View File

@@ -0,0 +1,15 @@
import type { CommonKeys } from "./CommonKeys"
export type Merge<Super, Self> = Omit<Super, CommonKeys<Self, Super>> & Self
export type MergeAll<T extends readonly object[]> =
T extends readonly [
infer Super,
infer Self,
...infer Rest extends readonly object[],
]
? MergeAll<readonly [Merge<Super, Self>, ...Rest]>
: T extends readonly [infer Self]
? Self
: {}

View File

@@ -1 +1,4 @@
export * from "./CommonKeys"
export * from "./Extend"
export * from "./Merge"
export * from "./StaticType" export * from "./StaticType"

View File

@@ -1,7 +1,21 @@
import { Schema as S } from "@effect/schema" import { Schema as S } from "@effect/schema"
import { reaction, runInAction } from "mobx" import { reaction, runInAction } from "mobx"
import type { Simplify } from "type-fest"
import { Jsonifiable, MutableTaggedClass } from "./Schema" import { Jsonifiable, MutableTaggedClass } from "./Schema"
import { ObservableClass } from "./Schema/MobX" import { ObservableClass } from "./Schema/MobX"
import type { ExtendAll } from "./Types"
type TestA = {
heugneu: string
type: "Type1" | "Type2"
}
type TestB = {
type: "Type1"
}
type Merged = Simplify<ExtendAll<[TestA, TestB]>>
class User extends MutableTaggedClass<User>()("User", { class User extends MutableTaggedClass<User>()("User", {