@ptolemy2002/ts-utils 2.2.0 → 2.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 +9 -0
- package/dist/index.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,9 @@ Given a type `T`, this type loops through every key `K` and wraps that key's val
|
|
|
24
24
|
### MaybePromise<T>
|
|
25
25
|
This type returns a union of the type `T` and a promise that resolves to the type `T`.
|
|
26
26
|
|
|
27
|
+
### MaybeArray<T>
|
|
28
|
+
This type returns a union of the type `T` and an array of that type.
|
|
29
|
+
|
|
27
30
|
### TAndOthers<T, K extends keyof any = PropertyKey>
|
|
28
31
|
This type returns an object with all the properties of `T` and any number of other properties under keys that fit the type `K`. The additional properties will all have the type `any` because I couldn't figure out how to make them have a type that does not include `ValueOf<T>` due to the way Typescript handles mapped object types.
|
|
29
32
|
|
|
@@ -33,6 +36,12 @@ This type returns a union of all the keys in `T` that have a value assignable to
|
|
|
33
36
|
### PartialBy<T, K extends keyof T>
|
|
34
37
|
This type returns a type that is the same as `T` except that the keys in `K` are optional.
|
|
35
38
|
|
|
39
|
+
### AtLeastOne<T, U = {[K in keyof T]: Pick<T, K> }>
|
|
40
|
+
This type returns a type that is the same as `T` except that at least one key is required.
|
|
41
|
+
|
|
42
|
+
### Override<T, U>
|
|
43
|
+
This type returns a type that is the same as `T` except that the keys in `U` are overridden with the values in `U`.
|
|
44
|
+
|
|
36
45
|
### Rename<T, K extends keyof T, N extends string>
|
|
37
46
|
This type returns a type that is the same as `T` except that the key `K` is renamed to `N`.
|
|
38
47
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type MaybeTransformerRecord<T, Args extends any[] = []> = {
|
|
|
4
4
|
[K in keyof T]: MaybeTransformer<T[K], Args>;
|
|
5
5
|
};
|
|
6
6
|
export type MaybePromise<T> = T | Promise<T>;
|
|
7
|
+
export type MaybeArray<T> = T | T[];
|
|
7
8
|
export type TAndOthers<T, K extends keyof any = PropertyKey> = Record<K, any> & T;
|
|
8
9
|
export type KeysMatching<T, V> = {
|
|
9
10
|
[K in keyof T]-?: T[K] extends V ? K : never;
|
|
@@ -22,6 +23,7 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
22
23
|
export type AtLeastOne<T, U = {
|
|
23
24
|
[K in keyof T]: Pick<T, K>;
|
|
24
25
|
}> = Partial<T> & U[keyof U];
|
|
26
|
+
export type Override<T, U> = Omit<T, keyof U> & U;
|
|
25
27
|
export type AdvancedConditionConstructorArgs<T> = {
|
|
26
28
|
include?: T | false | ((v: T) => boolean) | (T | false | ((v: T) => boolean) | false)[];
|
|
27
29
|
exclude?: T | false | ((v: T) => boolean) | (T | false | ((v: T) => boolean | false))[];
|