0.1.8 #9
@@ -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
4
src/Types/CommonKeys.ts
Normal 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
54
src/Types/Extend.ts
Normal 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
15
src/Types/Merge.ts
Normal 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
|
||||||
|
: {}
|
||||||
@@ -1 +1,4 @@
|
|||||||
|
export * from "./CommonKeys"
|
||||||
|
export * from "./Extend"
|
||||||
|
export * from "./Merge"
|
||||||
export * from "./StaticType"
|
export * from "./StaticType"
|
||||||
|
|||||||
14
src/tests.ts
14
src/tests.ts
@@ -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", {
|
||||||
|
|||||||
Reference in New Issue
Block a user