Comparing version 3.3.0 to 3.4.0
/** | ||
* Merges types without merging types of properties. | ||
*/ | ||
export type Combine<T1, T2, T3 = {}, T4 = {}> = T1 | ||
& Omit<T2, keyof T1> | ||
& Omit<T3, keyof T1 | keyof T2> | ||
& Omit<T4, keyof T1 | keyof T2 | keyof T3>; | ||
export type Combine<T1, T2, T3 = {}, T4 = {}> = T1 & | ||
Omit<T2, keyof T1> & | ||
Omit<T3, keyof T1 | keyof T2> & | ||
Omit<T4, keyof T1 | keyof T2 | keyof T3>; |
@@ -11,9 +11,13 @@ import { IfNoDeepValue } from './helpers.js'; | ||
export type DTO<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined | Function>, never, K>)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined | null> extends (infer U)[] ? DTO<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined | null>> extends true ? Exclude<T[K], undefined | null> | ||
// Deep process objects | ||
: DTO<Exclude<T[K], undefined | null>> | ||
[K in keyof T as IfNever< | ||
Exclude<T[K], undefined | Function>, | ||
never, | ||
K | ||
>]: Exclude<T[K], undefined | null> extends (infer U)[] // Deep process arrays | ||
? DTO<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined | null>> extends true | ||
? Exclude<T[K], undefined | null> | ||
: // Deep process objects | ||
DTO<Exclude<T[K], undefined | null>>; | ||
}; | ||
@@ -20,0 +24,0 @@ |
@@ -7,18 +7,28 @@ import { IfAny, IfClass, IfTuple } from './type-check'; | ||
*/ | ||
export type IfNoDeepValue<T> = | ||
T extends Builtin ? true | ||
: IfAny<T> extends true ? T | ||
: IfTuple<T> extends true ? true | ||
: T extends Function ? true | ||
: IfClass<T> extends true ? true | ||
: T extends Map<any, any> ? true | ||
: T extends ReadonlyMap<any, any> ? true | ||
: T extends WeakMap<any, any> ? true | ||
: T extends Set<any> ? true | ||
: T extends ReadonlySet<any> ? true | ||
: T extends WeakSet<any> ? true | ||
: T extends any[] ? true | ||
: false; | ||
export type IfNoDeepValue<T> = T extends Builtin | ||
? true | ||
: IfAny<T> extends true | ||
? T | ||
: IfTuple<T> extends true | ||
? true | ||
: T extends Function | ||
? true | ||
: IfClass<T> extends true | ||
? true | ||
: T extends Map<any, any> | ||
? true | ||
: T extends ReadonlyMap<any, any> | ||
? true | ||
: T extends WeakMap<any, any> | ||
? true | ||
: T extends Set<any> | ||
? true | ||
: T extends ReadonlySet<any> | ||
? true | ||
: T extends WeakSet<any> | ||
? true | ||
: T extends any[] | ||
? true | ||
: false; | ||
/** | ||
@@ -29,2 +39,1 @@ * ValuesOf | ||
export type ValuesOf<T> = T[keyof T]; | ||
@@ -1,15 +0,61 @@ | ||
export * from "./combine"; | ||
export * from "./dto"; | ||
export * from "./helpers"; | ||
export * from "./logical.js"; | ||
export * from "./mutable"; | ||
export * from "./nullish"; | ||
export * from "./omit"; | ||
export * from "./omit-never"; | ||
export * from "./opaque"; | ||
export * from "./partial"; | ||
export * from "./pick"; | ||
export * from "./readonly"; | ||
export * from "./required"; | ||
export * from "./type-check"; | ||
export * from "./types"; | ||
// noinspection JSUnusedGlobalSymbols | ||
import { DeeperMutable, DeepMutable, Mutable } from './mutable'; | ||
import { DeeperPartial, DeepPartial } from './partial'; | ||
import { DeeperReadonly, DeepReadonly } from './readonly'; | ||
import { DeeperRequired, DeepRequired } from './required'; | ||
export * from './combine'; | ||
export * from './dto'; | ||
export * from './helpers'; | ||
export * from './logical'; | ||
export * from './mutable'; | ||
export * from './nullish'; | ||
export * from './omit'; | ||
export * from './omit-never'; | ||
export * from './opaque'; | ||
export * from './partial'; | ||
export * from './pick'; | ||
export * from './readonly'; | ||
export * from './required'; | ||
export * from './type-check'; | ||
export * from './types'; | ||
declare function asMutable<T>(x: T): Mutable<T>; | ||
declare function asDeepMutable<T>(x: T): DeepMutable<T>; | ||
declare function asDeeperMutable<T>(x: T): DeeperMutable<T>; | ||
declare function asReadonly<T>(x: T): Readonly<T>; | ||
declare function asDeepReadonly<T>(x: T): DeepReadonly<T>; | ||
declare function asDeeperReadonly<T>(x: T): DeeperReadonly<T>; | ||
declare function asPartial<T>(x: T): Partial<T>; | ||
declare function asDeepPartial<T>(x: T): DeepPartial<T>; | ||
declare function asDeeperPartial<T>(x: T): DeeperPartial<T>; | ||
declare function asRequired<T>(x: T): Required<T>; | ||
declare function asDeepRequired<T>(x: T): DeepRequired<T>; | ||
declare function asDeeperRequired<T>(x: T): DeeperRequired<T>; | ||
export { | ||
asMutable, | ||
asDeepMutable, | ||
asDeeperMutable, | ||
asReadonly, | ||
asDeepReadonly, | ||
asDeeperReadonly, | ||
asPartial, | ||
asDeepPartial, | ||
asDeeperPartial, | ||
asRequired, | ||
asDeepRequired, | ||
asDeeperRequired, | ||
}; |
import { IfNever } from './type-check'; | ||
export type And<T1, T2, T3 = true, T4 = true, T5 = true, T6 = true> = | ||
IfNever<Exclude<T1, undefined | null | false>> extends true ? false : | ||
IfNever<Exclude<T2, undefined | null | false>> extends true ? false : | ||
IfNever<Exclude<T3, undefined | null | false>> extends true ? false : | ||
IfNever<Exclude<T4, undefined | null | false>> extends true ? false : | ||
IfNever<Exclude<T5, undefined | null | false>> extends true ? false : | ||
IfNever<Exclude<T6, undefined | null | false>> extends true ? false : | ||
true; | ||
IfNever<Exclude<T1, undefined | null | false>> extends true | ||
? false | ||
: IfNever<Exclude<T2, undefined | null | false>> extends true | ||
? false | ||
: IfNever<Exclude<T3, undefined | null | false>> extends true | ||
? false | ||
: IfNever<Exclude<T4, undefined | null | false>> extends true | ||
? false | ||
: IfNever<Exclude<T5, undefined | null | false>> extends true | ||
? false | ||
: IfNever<Exclude<T6, undefined | null | false>> extends true | ||
? false | ||
: true; | ||
export type Or<T1, T2, T3 = false, T4 = false, T5 = false, T6 = false> = | ||
IfNever<Exclude<T1, undefined | null | false>> extends false ? true : | ||
IfNever<Exclude<T2, undefined | null | false>> extends false ? true : | ||
IfNever<Exclude<T3, undefined | null | false>> extends false ? true : | ||
IfNever<Exclude<T4, undefined | null | false>> extends false ? true : | ||
IfNever<Exclude<T5, undefined | null | false>> extends false ? true : | ||
IfNever<Exclude<T6, undefined | null | false>> extends false ? true : | ||
false; | ||
IfNever<Exclude<T1, undefined | null | false>> extends false | ||
? true | ||
: IfNever<Exclude<T2, undefined | null | false>> extends false | ||
? true | ||
: IfNever<Exclude<T3, undefined | null | false>> extends false | ||
? true | ||
: IfNever<Exclude<T4, undefined | null | false>> extends false | ||
? true | ||
: IfNever<Exclude<T5, undefined | null | false>> extends false | ||
? true | ||
: IfNever<Exclude<T6, undefined | null | false>> extends false | ||
? true | ||
: false; |
@@ -8,3 +8,3 @@ import { IfNoDeepValue } from './helpers'; | ||
OmitReadonly, | ||
PickReadonly | ||
PickReadonly, | ||
} from './readonly'; | ||
@@ -17,12 +17,11 @@ import { IfNever } from './type-check'; | ||
export type Mutable<T> = { | ||
-readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: T[K]; | ||
-readonly [K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: T[K]; | ||
}; | ||
/** | ||
* Marks given keys as mutable | ||
*/ | ||
export type MutableSome<T, K extends keyof T> = Mutable<Pick<T, K>> & Omit<T, K>; | ||
export type MutableSome<T, K extends keyof T> = Mutable<Pick<T, K>> & | ||
Omit<T, K>; | ||
/** | ||
@@ -32,7 +31,10 @@ * Make all properties in T mutable deeply | ||
export type DeepMutable<T> = { | ||
-readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepMutable<Exclude<T[K], undefined>> | ||
-readonly [K in keyof T as IfNever< | ||
Exclude<T[K], undefined>, | ||
never, | ||
K | ||
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? T[K] | ||
: // Deep process objects | ||
DeepMutable<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -44,9 +46,13 @@ | ||
export type DeeperMutable<T> = { | ||
-readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperMutable<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperMutable<Exclude<T[K], undefined>> | ||
-readonly [K in keyof T as IfNever< | ||
Exclude<T[K], undefined>, | ||
never, | ||
K | ||
>]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays | ||
? DeeperMutable<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperMutable<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -88,2 +94,1 @@ | ||
export type DeeperOmitMutable<T> = DeeperPickReadonly<T>; | ||
@@ -7,7 +7,6 @@ import { IfNoDeepValue } from './helpers'; | ||
*/ | ||
export type NullishObject<T = null> ={ | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?: T[K] | null | ||
export type NullishObject<T = null> = { | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: T[K] | null; | ||
}; | ||
/** | ||
@@ -17,7 +16,8 @@ * Make all properties in T nullish deeply | ||
export type DeepNullish<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? (T[K] | null) | ||
// Deep process objects | ||
: DeepNullish<Exclude<T[K], undefined>> | null | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: IfNoDeepValue< // Do not deep process No-Deep values | ||
Exclude<T[K], undefined> | ||
> extends true | ||
? T[K] | null | ||
: // Deep process objects | ||
DeepNullish<Exclude<T[K], undefined>> | null; | ||
}; | ||
@@ -29,9 +29,12 @@ | ||
export type DeeperNullish<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperNullish<U>[] | null | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? (T[K] | null) | ||
// Deep process objects | ||
: DeeperNullish<Exclude<T[K], undefined>> | null | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: Exclude< // Deep process arrays | ||
T[K], | ||
undefined | ||
> extends (infer U)[] | ||
? DeeperNullish<U>[] | null | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | null | ||
: // Deep process objects | ||
DeeperNullish<Exclude<T[K], undefined>> | null; | ||
}; |
@@ -24,3 +24,3 @@ import { IfNoDeepValue } from './helpers'; | ||
export type OmitNever<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: T[K] | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: T[K]; | ||
}; | ||
@@ -32,7 +32,8 @@ | ||
export type DeepOmitNever<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepOmitNever<Exclude<T[K], undefined>> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: IfNoDeepValue< // Do not deep process No-Deep values | ||
Exclude<T[K], undefined> | ||
> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeepOmitNever<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -44,9 +45,12 @@ | ||
export type DeeperOmitNever<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitNever<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepOmitNever<Exclude<T[K], undefined>> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: Exclude< // Deep process arrays | ||
T[K], | ||
undefined | ||
> extends (infer U)[] | ||
? DeeperOmitNever<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeepOmitNever<Exclude<T[K], undefined>>; | ||
}; |
@@ -10,3 +10,3 @@ import { IfNoDeepValue } from './helpers'; | ||
export type StrictOmit<T, X extends keyof T> = { | ||
[K in keyof T as (K extends X ? never : K)]: T[K] | ||
[K in keyof T as K extends X ? never : K]: T[K]; | ||
}; | ||
@@ -18,10 +18,10 @@ | ||
export type OmitFunctions<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit functions | ||
IfFunction<Exclude<T[K], undefined>> | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit functions | ||
IfFunction<Exclude<T[K], undefined>> | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
@@ -33,3 +33,6 @@ | ||
export type OmitTypes<T, X> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined | X>, never, K>)]: Exclude<T[K], X> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined | X>, never, K>]: Exclude< | ||
T[K], | ||
X | ||
>; | ||
}; | ||
@@ -41,6 +44,10 @@ | ||
export type DeepOmitTypes<T, X> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined | X>, never, K>)]: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], X> | ||
// Deep process objects | ||
: DeepOmitTypes<Exclude<T[K], undefined>, X> | ||
[K in keyof T as IfNever< | ||
Exclude<T[K], undefined | X>, | ||
never, | ||
K | ||
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? Exclude<T[K], X> | ||
: // Deep process objects | ||
DeepOmitTypes<Exclude<T[K], undefined>, X>; | ||
}; | ||
@@ -52,8 +59,11 @@ | ||
export type DeeperOmitTypes<T, X> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined | X>, never, K>)]: // Do not deep process No-Deep values | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitTypes<U, X>[] | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], X> | ||
// Deep process objects | ||
: DeeperOmitTypes<Exclude<T[K], undefined>, X> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined | X>, never, K>]: Exclude< // Deep process arrays // Do not deep process No-Deep values | ||
T[K], | ||
undefined | ||
> extends (infer U)[] | ||
? DeeperOmitTypes<U, X>[] | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? Exclude<T[K], X> | ||
: // Deep process objects | ||
DeeperOmitTypes<Exclude<T[K], undefined>, X>; | ||
}; |
@@ -12,2 +12,2 @@ /** | ||
readonly [Symbols.brand]: N; | ||
} | ||
}; |
@@ -8,13 +8,12 @@ import { IfNoDeepValue } from './helpers'; | ||
OmitRequired, | ||
PickRequired | ||
PickRequired, | ||
} from './required'; | ||
import { IfNever } from './type-check'; | ||
/** | ||
* Marks given keys as optional | ||
*/ | ||
export type PartialSome<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>; | ||
export type PartialSome<T, K extends keyof T> = Partial<Pick<T, K>> & | ||
Omit<T, K>; | ||
/** | ||
@@ -24,7 +23,8 @@ * Partial but deeply | ||
export type DeepPartial<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepPartial<Exclude<T[K], undefined>> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: IfNoDeepValue< // Do not deep process No-Deep values | ||
Exclude<T[K], undefined> | ||
> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeepPartial<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -36,12 +36,14 @@ | ||
export type DeeperPartial<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperPartial<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperPartial<Exclude<T[K], undefined>> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: Exclude< // Deep process arrays | ||
T[K], | ||
undefined | ||
> extends (infer U)[] | ||
? DeeperPartial<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperPartial<Exclude<T[K], undefined>>; | ||
}; | ||
/** | ||
@@ -48,0 +50,0 @@ * OptionalKeys |
import { Or } from './logical.js'; | ||
import { OmitFunctions } from './omit'; | ||
import { IfAny, IfEmptyObject, IfFunction, IfNever, IfUnknown } from './type-check'; | ||
import { | ||
IfAny, | ||
IfEmptyObject, | ||
IfFunction, | ||
IfNever, | ||
IfUnknown, | ||
} from './type-check'; | ||
@@ -10,10 +16,10 @@ /** | ||
export type StrictPick<T, X extends keyof T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit X | ||
K extends X ? false : true | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit X | ||
K extends X ? false : true | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
@@ -25,13 +31,12 @@ | ||
export type PickFunctions<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit non functions | ||
IfFunction<Exclude<T[K], undefined>, false, true> | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit non functions | ||
IfFunction<Exclude<T[K], undefined>, false, true> | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
/** | ||
@@ -41,14 +46,12 @@ * Pick all function properties in T | ||
export type PickTypes<T, X> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit types which not exists in X | ||
T[K] extends X ? false : | ||
X extends T[K] ? false : true | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit types which not exists in X | ||
T[K] extends X ? false : X extends T[K] ? false : true | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
/** | ||
@@ -58,20 +61,18 @@ * Pick all function properties in T | ||
export type StrictPickTypes<T, X> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit unknown | ||
IfUnknown<T[K]>, | ||
// Omit any | ||
IfAny<T[K]>, | ||
// Omit {} | ||
IfEmptyObject<T[K]>, | ||
// Omit types which not exists in X | ||
T[K] extends X ? false : | ||
X extends T[K] ? false : true | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit unknown | ||
IfUnknown<T[K]>, | ||
// Omit any | ||
IfAny<T[K]>, | ||
// Omit {} | ||
IfEmptyObject<T[K]>, | ||
// Omit types which not exists in X | ||
T[K] extends X ? false : X extends T[K] ? false : true | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
/** | ||
@@ -87,3 +88,2 @@ * @desc Returns Function keys of an object | ||
/** | ||
@@ -98,2 +98,1 @@ * @desc Returns keys that match given type | ||
export type StrictKeysOfTypes<T, X> = keyof StrictPickTypes<T, X>; | ||
@@ -8,3 +8,4 @@ import { IfNoDeepValue } from './helpers'; | ||
*/ | ||
export type ReadonlySome<T, K extends keyof T> = Readonly<Pick<T, K>> & Omit<T, K>; | ||
export type ReadonlySome<T, K extends keyof T> = Readonly<Pick<T, K>> & | ||
Omit<T, K>; | ||
@@ -15,7 +16,10 @@ /** | ||
export type DeepReadonly<T> = { | ||
readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepReadonly<Exclude<T[K], undefined>> | ||
readonly [K in keyof T as IfNever< | ||
Exclude<T[K], undefined>, | ||
never, | ||
K | ||
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? T[K] | ||
: // Deep process objects | ||
DeepReadonly<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -27,12 +31,15 @@ | ||
export type DeeperReadonly<T> = { | ||
readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperReadonly<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperReadonly<Exclude<T[K], undefined>> | ||
readonly [K in keyof T as IfNever< | ||
Exclude<T[K], undefined>, | ||
never, | ||
K | ||
>]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays | ||
? DeeperReadonly<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperReadonly<Exclude<T[K], undefined>>; | ||
}; | ||
/** | ||
@@ -47,10 +54,10 @@ * Returns readonly keys of an object | ||
export type PickReadonly<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true> | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true> | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
@@ -62,13 +69,12 @@ | ||
export type OmitReadonly<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }> | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }> | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
/** | ||
@@ -78,14 +84,13 @@ * Pick all readonly properties in T deeply | ||
export type DeepPickReadonly<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true> | ||
> extends true ? never : K | ||
)]: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepPickReadonly<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true> | ||
> extends true | ||
? never | ||
: K]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? T[K] | ||
: // Deep process objects | ||
DeepPickReadonly<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -97,14 +102,13 @@ | ||
export type DeepOmitReadonly<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }> | ||
> extends true ? never : K | ||
)]: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepOmitReadonly<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }> | ||
> extends true | ||
? never | ||
: K]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? T[K] | ||
: // Deep process objects | ||
DeepOmitReadonly<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -116,16 +120,16 @@ | ||
export type DeeperPickReadonly<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true> | ||
> extends true ? never : K | ||
)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperPickReadonly<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperPickReadonly<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true> | ||
> extends true | ||
? never | ||
: K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays | ||
? DeeperPickReadonly<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperPickReadonly<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -137,16 +141,16 @@ | ||
export type DeeperOmitReadonly<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }> | ||
> extends true ? never : K | ||
)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitReadonly<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperOmitReadonly<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }> | ||
> extends true | ||
? never | ||
: K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays | ||
? DeeperOmitReadonly<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperOmitReadonly<Exclude<T[K], undefined>>; | ||
}; |
@@ -9,3 +9,7 @@ import { IfNoDeepValue } from './helpers'; | ||
*/ | ||
export type RequiredSome<T, K extends keyof T> = OmitTypes<Required<Pick<T, K>>, null> & Omit<T, K>; | ||
export type RequiredSome<T, K extends keyof T> = OmitTypes< | ||
Required<Pick<T, K>>, | ||
null | ||
> & | ||
Omit<T, K>; | ||
@@ -16,10 +20,12 @@ /** | ||
export type DeepRequired<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]-?: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], undefined> | ||
// Deep process objects | ||
: DeepRequired<Exclude<T[K], undefined>> | ||
[K in keyof T as IfNever< | ||
Exclude<T[K], undefined>, | ||
never, | ||
K | ||
>]-?: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? Exclude<T[K], undefined> | ||
: // Deep process objects | ||
DeepRequired<Exclude<T[K], undefined>>; | ||
}; | ||
/** | ||
@@ -29,9 +35,12 @@ * Make all properties in T required deeply including arrays | ||
export type DeeperRequired<T> = { | ||
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]-?: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperRequired<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], undefined> | ||
// Deep process objects | ||
: DeepRequired<Exclude<T[K], undefined>> | ||
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]-?: Exclude< // Deep process arrays | ||
T[K], | ||
undefined | ||
> extends (infer U)[] | ||
? DeeperRequired<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? Exclude<T[K], undefined> | ||
: // Deep process objects | ||
DeepRequired<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -45,3 +54,2 @@ | ||
/** | ||
@@ -51,10 +59,10 @@ * Pick all required properties in T | ||
export type PickRequired<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit optional | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }> | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit optional | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }> | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
@@ -66,10 +74,10 @@ | ||
export type OmitRequired<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit optional | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }, false, true> | ||
> extends true ? never : K | ||
)]: T[K] | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit optional | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }, false, true> | ||
> extends true | ||
? never | ||
: K]: T[K]; | ||
}; | ||
@@ -81,14 +89,13 @@ | ||
export type DeepPickRequired<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit optional | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }> | ||
> extends true ? never : K | ||
)]: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepPickRequired<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit optional | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }> | ||
> extends true | ||
? never | ||
: K]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? T[K] | ||
: // Deep process objects | ||
DeepPickRequired<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -100,14 +107,13 @@ | ||
export type DeepOmitRequired<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }> | ||
> extends true ? never : K | ||
)]?: | ||
// Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeepOmitRequired<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }> | ||
> extends true | ||
? never | ||
: K]?: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values | ||
? T[K] | ||
: // Deep process objects | ||
DeepOmitRequired<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -119,16 +125,16 @@ | ||
export type DeeperPickRequired<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }> | ||
> extends true ? never : K | ||
)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperPickRequired<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperPickRequired<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }> | ||
> extends true | ||
? never | ||
: K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays | ||
? DeeperPickRequired<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperPickRequired<Exclude<T[K], undefined>>; | ||
}; | ||
@@ -140,16 +146,16 @@ | ||
export type DeeperOmitRequired<T> = { | ||
[K in keyof T as ( | ||
Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }> | ||
> extends true ? never : K | ||
)]: | ||
// Deep process arrays | ||
Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitRequired<U>[] | ||
// Do not deep process No-Deep values | ||
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K] | ||
// Deep process objects | ||
: DeeperOmitRequired<Exclude<T[K], undefined>> | ||
[K in keyof T as Or< | ||
// Omit never keys | ||
IfNever<Exclude<T[K], undefined>>, | ||
// Omit required | ||
IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }> | ||
> extends true | ||
? never | ||
: K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays | ||
? DeeperOmitRequired<U>[] | ||
: // Do not deep process No-Deep values | ||
IfNoDeepValue<Exclude<T[K], undefined>> extends true | ||
? T[K] | ||
: // Deep process objects | ||
DeeperOmitRequired<Exclude<T[K], undefined>>; | ||
}; |
@@ -8,4 +8,3 @@ import { Primitive, Type } from './types'; | ||
*/ | ||
export type IfAny<T, Y = true, N = false> = | ||
0 extends 1 & T ? Y : N; | ||
export type IfAny<T, Y = true, N = false> = 0 extends 1 & T ? Y : N; | ||
@@ -15,4 +14,3 @@ /** | ||
*/ | ||
export type IfNever<T, Y = true, N = false> = | ||
[T] extends [never] ? Y : N; | ||
export type IfNever<T, Y = true, N = false> = [T] extends [never] ? Y : N; | ||
@@ -22,4 +20,3 @@ /** | ||
*/ | ||
export type IfUndefined<T, Y = true, N = false> = | ||
IfEquals<T, undefined, Y, N>; | ||
export type IfUndefined<T, Y = true, N = false> = IfEquals<T, undefined, Y, N>; | ||
@@ -29,4 +26,3 @@ /** | ||
*/ | ||
export type IfSymbol<T, Y = true, N = false> = | ||
IfEquals<T, symbol, Y, N>; | ||
export type IfSymbol<T, Y = true, N = false> = IfEquals<T, symbol, Y, N>; | ||
@@ -36,4 +32,3 @@ /** | ||
*/ | ||
export type IfUnknown<T, Y = true, N = false> = | ||
IfEquals<T, unknown, Y, N>; | ||
export type IfUnknown<T, Y = true, N = false> = IfEquals<T, unknown, Y, N>; | ||
@@ -43,4 +38,3 @@ /** | ||
*/ | ||
export type IfNull<T, Y = true, N = false> = | ||
IfEquals<T, null, Y, N>; | ||
export type IfNull<T, Y = true, N = false> = IfEquals<T, null, Y, N>; | ||
@@ -51,7 +45,10 @@ /** | ||
export type IfNullish<T, Y = true, N = false> = | ||
IfNever<T> extends true ? N | ||
: T extends null ? Y | ||
: T extends undefined ? Y : N; | ||
IfNever<T> extends true | ||
? N | ||
: T extends null | ||
? Y | ||
: T extends undefined | ||
? Y | ||
: N; | ||
/** | ||
@@ -61,8 +58,11 @@ * Returns Y if typeof T is a tuple, N otherwise | ||
export type IfTuple<T, Y = true, N = false> = | ||
IfEquals<T, [any]> extends true | ||
? T extends [any] | ||
? number extends T['length'] ? N : Y | ||
: N : N; | ||
IfEquals<T, [any]> extends true | ||
? T extends [any] | ||
? number extends T['length'] | ||
? N | ||
: Y | ||
: N | ||
: N; | ||
export type IfTupleOrAny<T, Y = true, N = false> = | ||
IfAny<T> extends true ? Y : IfTuple<T, Y, N>; | ||
IfAny<T> extends true ? Y : IfTuple<T, Y, N>; | ||
@@ -73,12 +73,18 @@ /** | ||
export type IfPrimitive<T, Y = true, N = false> = | ||
IfNever<T> extends true ? N : | ||
IfNull<T> extends true ? Y : | ||
IfUndefined<T> extends true ? Y : | ||
IfClass<T> extends true ? N : | ||
IfFunction<T> extends true ? N : | ||
T extends Primitive ? Y : | ||
N; | ||
IfNever<T> extends true | ||
? N | ||
: IfNull<T> extends true | ||
? Y | ||
: IfUndefined<T> extends true | ||
? Y | ||
: IfClass<T> extends true | ||
? N | ||
: IfFunction<T> extends true | ||
? N | ||
: T extends Primitive | ||
? Y | ||
: N; | ||
export type IfPrimitiveOrAny<T, Y = true, N = false> = | ||
IfAny<T> extends true ? Y : IfPrimitive<T, Y, N>; | ||
IfAny<T> extends true ? Y : IfPrimitive<T, Y, N>; | ||
@@ -88,4 +94,3 @@ /** | ||
*/ | ||
export type IfEmptyObject<T, Y = true, N = false> = | ||
IfEquals<T, {}, Y, N>; | ||
export type IfEmptyObject<T, Y = true, N = false> = IfEquals<T, {}, Y, N>; | ||
@@ -96,11 +101,12 @@ /** | ||
export type IfObject<T, Y = true, N = false> = | ||
IfNever<T> extends true ? N | ||
: T extends object | ||
? T extends NonObj | any[] | ||
? N | ||
: Y | ||
: N; | ||
IfNever<T> extends true | ||
? N | ||
: T extends object | ||
? T extends NonObj | any[] | ||
? N | ||
: Y | ||
: N; | ||
export type IfObjectOrAny<T, Y = true, N = false> = | ||
IfAny<T> extends true ? Y : IfObject<T, Y, N>; | ||
IfAny<T> extends true ? Y : IfObject<T, Y, N>; | ||
@@ -111,9 +117,6 @@ /** | ||
export type IfFunction<T, Y = true, N = false> = | ||
IfNever<T> extends true ? N | ||
: T extends Type ? N | ||
: T extends Function ? Y | ||
: N; | ||
IfNever<T> extends true ? N : T extends Type ? N : T extends Function ? Y : N; | ||
export type IfFunctionOrAny<T, Y = true, N = false> = | ||
IfAny<T> extends true ? Y : IfFunction<T, Y, N>; | ||
IfAny<T> extends true ? Y : IfFunction<T, Y, N>; | ||
@@ -124,10 +127,13 @@ /** | ||
export type IfClass<T, Y = true, N = false> = | ||
IfNever<T> extends true ? N | ||
: IfUndefined<T> extends true ? N | ||
: T extends Type ? Y : N; | ||
IfNever<T> extends true | ||
? N | ||
: IfUndefined<T> extends true | ||
? N | ||
: T extends Type | ||
? Y | ||
: N; | ||
export type IfClassOrAny<T, Y = true, N = false> = | ||
IfAny<T> extends true ? Y : IfClass<T, Y, N>; | ||
IfAny<T> extends true ? Y : IfClass<T, Y, N>; | ||
/** | ||
@@ -137,9 +143,16 @@ * Returns "Y" if "T1" is exactly same with "T2", "N" otherwise | ||
export type IfEquals<T1, T2, Y = true, N = false> = | ||
IfObject<T1> | IfObject<T2> extends true | ||
? ((<G>() => G extends EqualsWrapped<T1> ? 1 : 2) extends (<G>() => G extends EqualsWrapped<T2> ? 1 : 2) ? Y : N) | ||
: ((<G>() => G extends T1 ? 1 : 2) extends (<G>() => G extends T2 ? 1 : 2) ? Y : N); | ||
| IfObject<T1> | ||
| IfObject<T2> extends true | ||
? (<G>() => G extends EqualsWrapped<T1> ? 1 : 2) extends < | ||
G, | ||
>() => G extends EqualsWrapped<T2> ? 1 : 2 | ||
? Y | ||
: N | ||
: (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 | ||
? Y | ||
: N; | ||
type EqualsWrapped<T> = T extends infer R & {} | ||
? { [P in keyof R]: R[P] } | ||
: never; | ||
? { [P in keyof R]: R[P] } | ||
: never; | ||
@@ -150,20 +163,47 @@ /** | ||
export type IfCompatible<T1, T2, Y = true, N = false> = | ||
IfUndefined<T1> extends true ? IfEquals<T1, T2, Y, N> : IfUndefined<T2> extends true ? N | ||
: IfNever<T1> extends true ? IfEquals<T1, T2, Y, N> : IfNever<T2> extends true ? N | ||
: IfNull<T1> extends true ? IfEquals<T1, T2, Y, N> : IfNull<T2> extends true ? N | ||
: IfUnknown<T1> extends true ? Y : IfUnknown<T2> extends true ? Y | ||
: IfAny<T1> extends true ? Y : IfAny<T2> extends true ? Y | ||
: IfEmptyObject<T1> extends true ? IfObject<T2, Y, N> | ||
: IfEmptyObject<T2> extends true ? IfObject<T1, Y, N> | ||
: IfFunction<T1> extends true ? IfCompatibleFunction<T1, T2, Y, N> | ||
: IfObject<T1> extends true ? [T1] extends [T2] ? Y : N | ||
: [T1] extends [T2] ? Y | ||
: IfPrimitive<T2> extends true ? [T2] extends [T1] ? Y | ||
: N : N; | ||
IfUndefined<T1> extends true | ||
? IfEquals<T1, T2, Y, N> | ||
: IfUndefined<T2> extends true | ||
? N | ||
: IfNever<T1> extends true | ||
? IfEquals<T1, T2, Y, N> | ||
: IfNever<T2> extends true | ||
? N | ||
: IfNull<T1> extends true | ||
? IfEquals<T1, T2, Y, N> | ||
: IfNull<T2> extends true | ||
? N | ||
: IfUnknown<T1> extends true | ||
? Y | ||
: IfUnknown<T2> extends true | ||
? Y | ||
: IfAny<T1> extends true | ||
? Y | ||
: IfAny<T2> extends true | ||
? Y | ||
: IfEmptyObject<T1> extends true | ||
? IfObject<T2, Y, N> | ||
: IfEmptyObject<T2> extends true | ||
? IfObject<T1, Y, N> | ||
: IfFunction<T1> extends true | ||
? IfCompatibleFunction<T1, T2, Y, N> | ||
: IfObject<T1> extends true | ||
? [T1] extends [T2] | ||
? Y | ||
: N | ||
: [T1] extends [T2] | ||
? Y | ||
: IfPrimitive<T2> extends true | ||
? [T2] extends [T1] | ||
? Y | ||
: N | ||
: N; | ||
type IfCompatibleFunction<T1, T2, Y = true, N = false> = | ||
IfFunction<T1> extends false ? N | ||
: IfFunction<T2> extends false ? N | ||
: T1 extends T2 | ||
? Y | ||
: N; | ||
IfFunction<T1> extends false | ||
? N | ||
: IfFunction<T2> extends false | ||
? N | ||
: T1 extends T2 | ||
? Y | ||
: N; |
@@ -16,7 +16,9 @@ /** | ||
getReader(options: { mode: "byob" }): ReadableStreamBYOBReader; | ||
getReader(options: { mode: 'byob' }): ReadableStreamBYOBReader; | ||
getReader(): ReadableStreamDefaultReader<R>; | ||
getReader(options?: ReadableStreamGetReaderOptions): ReadableStreamReader<R>; | ||
getReader( | ||
options?: ReadableStreamGetReaderOptions, | ||
): ReadableStreamReader<R>; | ||
} | ||
@@ -39,3 +41,2 @@ | ||
/** | ||
@@ -52,5 +53,4 @@ * Primitive | ||
*/ | ||
type JsonType = BasicPrimitive | null | object | (BasicPrimitive | object)[] | ||
type JsonType = BasicPrimitive | null | object | (BasicPrimitive | object)[]; | ||
/** | ||
@@ -60,6 +60,24 @@ * Builtin | ||
*/ | ||
export type Builtin = Primitive | Function | String | Number | Date | Error | RegExp | | ||
Buffer | ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray | | ||
Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | | ||
URL | ReadableStream | WritableStream; | ||
export type Builtin = | ||
| Primitive | ||
| Function | ||
| String | ||
| Number | ||
| Date | ||
| Error | ||
| RegExp | ||
| Buffer | ||
| ArrayBuffer | ||
| Int8Array | ||
| Uint8Array | ||
| Uint8ClampedArray | ||
| Int16Array | ||
| Uint16Array | ||
| Int32Array | ||
| Uint32Array | ||
| Float32Array | ||
| Float64Array | ||
| URL | ||
| ReadableStream | ||
| WritableStream; | ||
@@ -71,3 +89,3 @@ /** | ||
export interface Type<T = any> { | ||
new(...args: any[]): T; | ||
new (...args: any[]): T; | ||
} | ||
@@ -79,6 +97,8 @@ | ||
*/ | ||
export type Class<Args extends any[] = any[], Instance = {}, Static = {}> = | ||
(new(...args: Args) => Instance) & Static; | ||
export type Class< | ||
Args extends any[] = any[], | ||
Instance = {}, | ||
Static = {}, | ||
> = (new (...args: Args) => Instance) & Static; | ||
/** | ||
@@ -96,8 +116,6 @@ * Maybe | ||
export type Awaited<T> = T extends PromiseLike<infer U> ? U : T; | ||
export type Thunk<T> = T | (() => T); | ||
export type ThunkAsync<T> = Thunk<T> | (() => Promise<T>) | ||
export type ThunkAsync<T> = Thunk<T> | (() => Promise<T>); | ||
export type TypeThunk<T = any> = Thunk<Type<T>>; | ||
@@ -108,3 +126,2 @@ export type TypeThunkAsync<T = any> = ThunkAsync<Type<T>>; | ||
/** | ||
@@ -120,3 +137,5 @@ * PropertyType | ||
*/ | ||
export type ElementType<T extends { [P in K & any]: any }, | ||
K extends keyof T | number> = T[K]; | ||
export type ElementType< | ||
T extends { [P in K & any]: any }, | ||
K extends keyof T | number, | ||
> = T[K]; |
@@ -15,6 +15,7 @@ { | ||
], | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"type": "module", | ||
"module": "lib/index.mjs", | ||
"main": "lib/index.cjs", | ||
"types": "lib/index.d.ts", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"repository": "git@github.com:panates/ts-gems.git", | ||
@@ -26,4 +27,5 @@ "author": "Eray Hanoglu <e.hanoglu@panates.com>", | ||
"lint": "eslint --no-error-on-unmatched-pattern", | ||
"test:common": "jest --clearCache && jest --config=./jest.config.js", | ||
"test:nostrict": "jest --clearCache && jest --config=./jest.nostrict.config.js", | ||
"format": "prettier . --write --log-level=warn", | ||
"test:common": "jest --clearCache && jest --config=./jest.config.mjs", | ||
"test:nostrict": "jest --clearCache && jest --config=./jest.nostrict.config.mjs", | ||
"test": "npm run test:common && npm run test:nostrict" | ||
@@ -38,4 +40,11 @@ }, | ||
"@types/jest": "^29.5.12", | ||
"eslint": "^9.0.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-security": "^3.0.0", | ||
"eslint-plugin-simple-import-sort": "^12.1.0", | ||
"eslint-plugin-unused-imports": "^3.1.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.2.5", | ||
"ts-jest": "^29.1.2", | ||
@@ -42,0 +51,0 @@ "typescript": "^5.4.5" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35127
20
1119
Yes
12