@ptolemy2002/ts-utils 3.2.0 → 3.3.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/README.md CHANGED
@@ -106,6 +106,20 @@ This type returns an intersection of all the possible values in an object of typ
106
106
  ### Contains<L extends unknown[], T>
107
107
  This type returns a boolean indicating whether the type `T` is contained in the array `L`.
108
108
 
109
+ ### ArrayWithOptional<AR extends unknown[], AO extends unknown[]>
110
+ This type returns a union of the array `AR` and an array that consists of all the elements of `AR` followed by all the elements of `AO`. You can chain it for multiple optional segments, like so:
111
+ ```typescript
112
+ type MyArray = ArrayWithOptional<[number, string], ArrayWithOptional<[boolean], [Date]>>;
113
+ ```
114
+
115
+ The resulting type `MyArray` would be equivalent to:
116
+ ```typescript
117
+ type MyArray =
118
+ | [number, string]
119
+ | [number, string, boolean]
120
+ | [number, string, boolean, Date];
121
+ ```
122
+
109
123
  ## Functions
110
124
  The following functions are available in the library:
111
125
 
package/dist/index.d.ts CHANGED
@@ -28,14 +28,15 @@ export type Override<T, U> = Omit<T, keyof U> & U;
28
28
  export declare const advancedConditionSymbol: unique symbol;
29
29
  export type AdvancedCondition<T> = Branded<{
30
30
  __isAdvancedCondition: true;
31
- include?: T | false | ((v: T) => boolean) | (T | false | ((v: T) => boolean) | false)[];
32
- exclude?: T | false | ((v: T) => boolean) | (T | false | ((v: T) => boolean | false))[];
31
+ include?: T | false | ((v: T) => boolean) | (T | false | ((v: T) => boolean))[];
32
+ exclude?: T | false | ((v: T) => boolean) | (T | false | ((v: T) => boolean))[];
33
33
  match?: (a: T, b: T) => boolean;
34
34
  }, [typeof advancedConditionSymbol]>;
35
- export type SerializableAdvancedCondition<T> = Override<Omit<AdvancedCondition<T>, "match">, {
36
- include?: Exclude<AdvancedCondition<T>["include"], () => any>;
37
- exclude?: Exclude<AdvancedCondition<T>["exclude"], () => any>;
38
- }>;
35
+ export type SerializableAdvancedCondition<T> = Branded<{
36
+ __isAdvancedCondition: true;
37
+ include?: T | false | (T | false)[];
38
+ exclude?: T | false | (T | false)[];
39
+ }, [typeof advancedConditionSymbol]>;
39
40
  export declare function isAdvancedCondition(value: any): value is AdvancedCondition<any>;
40
41
  export declare function createAdvancedCondition<T>(condition: WithoutBrand<Omit<AdvancedCondition<T>, "__isAdvancedCondition">>): AdvancedCondition<T>;
41
42
  export declare function createSerializableAdvancedCondition<T>(condition: WithoutBrand<Omit<SerializableAdvancedCondition<T>, "__isAdvancedCondition">>): SerializableAdvancedCondition<T>;
@@ -56,3 +57,4 @@ export type ValuesIntersection<T> = ValueOf<{
56
57
  }> extends (x: infer I) => void ? I : never;
57
58
  export type Contains<L extends unknown[], T> = L extends [...unknown[], T] ? true : L extends [T, ...unknown[]] ? true : L extends [T] ? true : false;
58
59
  export declare function omit<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
60
+ export type ArrayWithOptional<AR extends unknown[], AO extends unknown[]> = AR | [...AR, ...AO];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/ts-utils",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",