@ptolemy2002/ts-utils 3.2.1 → 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 +14 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
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
|
@@ -57,3 +57,4 @@ export type ValuesIntersection<T> = ValueOf<{
|
|
|
57
57
|
}> extends (x: infer I) => void ? I : never;
|
|
58
58
|
export type Contains<L extends unknown[], T> = L extends [...unknown[], T] ? true : L extends [T, ...unknown[]] ? true : L extends [T] ? true : false;
|
|
59
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];
|