ts-essentials
Advanced tools
Comparing version 2.0.11 to 3.0.0-beta.0
@@ -9,18 +9,33 @@ /** Essentials */ | ||
/** Like Partial but recursive */ | ||
export declare type DeepPartial<T> = { | ||
[P in keyof T]?: T[P] extends Primitive ? T[P] : T[P] extends Function ? T[P] : T[P] extends Date ? T[P] : T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>; | ||
}; | ||
export declare type DeepPartial<T> = T extends Primitive ? T : T extends Function ? T : T extends Date ? T : T extends Map<infer K, infer V> ? DeepPartialMap<K, V> : T extends Set<infer U> ? DeepPartialSet<U> : T extends {} ? { | ||
[K in keyof T]?: DeepPartial<T[K]>; | ||
} : Partial<T>; | ||
interface DeepPartialSet<ItemType> extends Set<DeepPartial<ItemType>> { | ||
} | ||
interface DeepPartialMap<KeyType, ValueType> extends Map<DeepPartial<KeyType>, DeepPartial<ValueType>> { | ||
} | ||
/** Like NonNullable but recursive */ | ||
export declare type DeepNonNullable<T> = T extends Primitive ? NonNullable<T> : T extends Function ? NonNullable<T> : T extends Date ? NonNullable<T> : T extends Map<infer K, infer V> ? NonNullableMap<K, V> : T extends Set<infer U> ? NonNullableSet<U> : T extends {} ? { | ||
[K in keyof T]: DeepNonNullable<T[K]>; | ||
} : NonNullable<T>; | ||
interface NonNullableSet<ItemType> extends Set<DeepNonNullable<ItemType>> { | ||
} | ||
interface NonNullableMap<KeyType, ValueType> extends Map<DeepNonNullable<KeyType>, DeepNonNullable<ValueType>> { | ||
} | ||
/** Like Required but recursive */ | ||
export declare type DeepRequired<T> = T extends Primitive ? NonNullable<T> : T extends any[] ? DeepRequiredArray<NonNullable<T[number]>> : T extends {} ? { | ||
[K in keyof T]-?: DeepRequired<NonNullable<T[K]>>; | ||
} : T; | ||
interface DeepRequiredArray<T> extends Array<DeepRequired<T>> { | ||
export declare type DeepRequired<T> = T extends Primitive ? NonNullable<T> : T extends Function ? NonNullable<T> : T extends Date ? NonNullable<T> : T extends Map<infer K, infer V> ? RequiredMap<K, V> : T extends Set<infer U> ? RequiredSet<U> : T extends {} ? { | ||
[K in keyof T]-?: DeepRequired<T[K]>; | ||
} : NonNullable<T>; | ||
interface RequiredSet<ItemType> extends Set<DeepRequired<ItemType>> { | ||
} | ||
interface RequiredMap<KeyType, ValueType> extends Map<DeepRequired<KeyType>, DeepRequired<ValueType>> { | ||
} | ||
/** Like Readonly but recursive */ | ||
export declare type DeepReadonly<T> = T extends Primitive ? T : T extends (any[] | ReadonlyArray<any>) ? DeepReadonlyArray<T[number]> : T extends Function ? T : T extends {} ? DeepReadonlyObject<T> : unknown; | ||
declare type DeepReadonlyObject<T> = { | ||
readonly [P in keyof T]: DeepReadonly<T[P]>; | ||
}; | ||
interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> { | ||
export declare type DeepReadonly<T> = T extends Primitive ? T : T extends Function ? T : T extends Date ? T : T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : T extends Set<infer U> ? ReadonlySet<U> : T extends {} ? { | ||
readonly [K in keyof T]: DeepReadonly<T[K]>; | ||
} : Readonly<T>; | ||
interface ReadonlySet<ItemType> extends Set<DeepReadonly<ItemType>> { | ||
} | ||
interface ReadonlyMap<KeyType, ValueType> extends Map<DeepReadonly<KeyType>, DeepReadonly<ValueType>> { | ||
} | ||
/** Make readonly object writable */ | ||
@@ -31,8 +46,9 @@ export declare type Writable<T> = { | ||
/** Like Writable but recursive */ | ||
export declare type DeepWritable<T> = T extends Primitive ? T : T extends (any[] | ReadonlyArray<any>) ? WritableArray<T[number]> : T extends Function ? T : DeepWritableObject<T>; | ||
declare type DeepWritableObject<T> = { | ||
-readonly [P in keyof T]: DeepWritable<T[P]>; | ||
}; | ||
interface WritableArray<T> extends Array<DeepWritable<T>> { | ||
export declare type DeepWritable<T> = T extends Primitive ? T : T extends Function ? T : T extends Date ? T : T extends Map<infer K, infer V> ? WritableMap<K, V> : T extends Set<infer U> ? WritableSet<U> : T extends {} ? { | ||
-readonly [K in keyof T]: DeepWritable<T[K]>; | ||
} : T; | ||
interface WritableSet<ItemType> extends Set<DeepWritable<ItemType>> { | ||
} | ||
interface WritableMap<KeyType, ValueType> extends Map<DeepWritable<KeyType>, DeepReadonly<ValueType>> { | ||
} | ||
/** | ||
@@ -39,0 +55,0 @@ * Omit given key in object type |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "2.0.11", | ||
"version": "3.0.0-beta.0", | ||
"main": "dist/index.js", | ||
@@ -27,7 +27,7 @@ "types": "dist/index.d.ts", | ||
"@codechecks/build-size-watcher": "^0.1.0", | ||
"@codechecks/client": "^0.1.0", | ||
"conditional-type-checks": "^0.5.0", | ||
"prettier": "^1.16.1", | ||
"typescript": "^3.2.2" | ||
"@codechecks/client": "^0.1.1-beta.0", | ||
"conditional-type-checks": "^1.0.1", | ||
"prettier": "^1.18.2", | ||
"typescript": "^3.5.2" | ||
} | ||
} |
@@ -28,23 +28,23 @@ <p align="center"> | ||
- [Basic](#basic) | ||
- Primitive | ||
- [Dictionaries](#dictionaries) | ||
- Dictionary | ||
- DictionaryValues | ||
- [Deep Partial & DeepRequired & Deep Readonly](#deep-partial--deep-required--deep-readonly) | ||
- [Writable & DeepWritable](#writable) | ||
- [Omit](#omit) | ||
- [OmitProperties](#omitproperties) | ||
- [NonNever](#nonnever) | ||
- [Merge](#merge) | ||
- [MarkRequired](#markrequired) | ||
- [ReadonlyKeys](#readonlykeys) | ||
- [WritableKeys](#writablekeys) | ||
- [UnionToIntersection](#uniontointersection) | ||
- [Opaque types](#opaque-types) | ||
- [Tuple constraint](#tuple-constraint) | ||
- [Literal types](#literal-types) | ||
- [Exhaustive switch cases](#exhaustive-switch-cases) | ||
- [ValueOf](#valueof-type) | ||
- [AsyncOrSync](#asyncorsync-type) | ||
- [Install](#Install) | ||
- [What's inside?](#Whats-inside) | ||
- [Basic:](#Basic) | ||
- [Dictionaries](#Dictionaries) | ||
- [Deep Partial & Deep Required & Deep Readonly & Deep NonNullable](#Deep-Partial--Deep-Required--Deep-Readonly--Deep-NonNullable) | ||
- [Writable](#Writable) | ||
- [Omit](#Omit) | ||
- [OmitProperties](#OmitProperties) | ||
- [NonNever](#NonNever) | ||
- [Merge](#Merge) | ||
- [MarkRequired](#MarkRequired) | ||
- [ReadonlyKeys](#ReadonlyKeys) | ||
- [WritableKeys](#WritableKeys) | ||
- [UnionToIntersection](#UnionToIntersection) | ||
- [Opaque types](#Opaque-types) | ||
- [Tuple constraint](#Tuple-constraint) | ||
- [Literal types](#Literal-types) | ||
- [Exhaustive switch cases](#Exhaustive-switch-cases) | ||
- [ValueOf type](#ValueOf-type) | ||
- [AsyncOrSync type](#AsyncOrSync-type) | ||
- [Contributors](#Contributors) | ||
@@ -82,3 +82,3 @@ ### Basic: | ||
### Deep Partial & Deep Required & Deep Readonly | ||
### Deep Partial & Deep Required & Deep Readonly & Deep NonNullable | ||
@@ -106,3 +106,3 @@ ```typescript | ||
a: "test", | ||
array: [], | ||
array: [{bar: 1}], | ||
}, | ||
@@ -112,2 +112,19 @@ }; | ||
type ComplexObjectReadonly = DeepReadonly<ComplexObject>; | ||
type ComplexNullableObject = { | ||
simple: number | null | undefined; | ||
nested: { | ||
a: string | null | undefined; | ||
array: [{ bar: number | null | undefined }] | null | undefined; | ||
}; | ||
}; | ||
type ComplexObjectNonNullable = DeepNonNullable<ComplexNullableObject>; | ||
const sampleNonNullable: ComplexObjectNonNullable = { | ||
simple: 5, | ||
nested: { | ||
a: "test", | ||
array: [{bar: null}], // Error: Type 'null' is not assignable to type 'number' | ||
} | ||
} | ||
``` | ||
@@ -114,0 +131,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
22596
122
418
2