@trackunit/shared-utils 0.0.23 → 0.0.28-alpha-9c359562be.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/typeUtils.d.ts +23 -0
package/package.json
CHANGED
package/src/typeUtils.d.ts
CHANGED
|
@@ -29,4 +29,27 @@ type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T;
|
|
|
29
29
|
*
|
|
30
30
|
*/
|
|
31
31
|
export declare const truthy: <T>(value: T) => value is Truthy<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a type by excluding specified keys from another type in a homomorphic manner.
|
|
34
|
+
* Homomorphic types maintain the same shape as the original type but exclude specified keys.
|
|
35
|
+
* For example works correctly on descriminated unions whereas Omit messes up the type.
|
|
36
|
+
* https://github.com/microsoft/TypeScript/issues/54451
|
|
37
|
+
*
|
|
38
|
+
* @template T - The original type.
|
|
39
|
+
* @template K - The keys to be excluded from the original type.
|
|
40
|
+
* @property {T} P - The resulting type excluding the keys specified by K while preserving the original structure.
|
|
41
|
+
*/
|
|
42
|
+
export type MappedOmit<T, K extends keyof T> = {
|
|
43
|
+
[P in keyof T as P extends K ? never : P]: T[P];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new type by making a specific property optional within the original type.
|
|
47
|
+
*
|
|
48
|
+
* @template BaseType - The original type from which a property will be made optional.
|
|
49
|
+
* @template OptionalProp - The key of the property to be made optional.
|
|
50
|
+
* @param {BaseType} obj - The object whose property needs to be made optional.
|
|
51
|
+
* @param {OptionalProp} propKey - The key of the property to be made optional.
|
|
52
|
+
* @returns {Omit<BaseType, OptionalProp> & Partial<Pick<BaseType, OptionalProp>>} - A type with the specified property made optional.
|
|
53
|
+
*/
|
|
54
|
+
export type MakePropertyOptional<BaseType, OptionalProp extends keyof BaseType> = MappedOmit<BaseType, OptionalProp> & Partial<Pick<BaseType, OptionalProp>>;
|
|
32
55
|
export {};
|