From d3550c9845c8a278e4f210fd88e7eb193c738c5c Mon Sep 17 00:00:00 2001 From: Kaspars Zarinovs Date: Wed, 25 May 2022 01:17:49 +0300 Subject: [PATCH 1/3] Added a few handy global utility types --- src/types/global.d.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/types/global.d.ts diff --git a/src/types/global.d.ts b/src/types/global.d.ts new file mode 100644 index 0000000..513e617 --- /dev/null +++ b/src/types/global.d.ts @@ -0,0 +1,19 @@ +export {}; + +declare global { + /** + * Allows extracting all possible values of another type. + */ + type ValueOf = T[keyof T]; + + /** + * Like Partial utility type, only this allows specifying select keys + * to be made optional instead of all keys. + */ + type Optional = Partial> & Omit + + /** + * A slightly nicer way of defining nullable types. + */ + type Nullable = T | null; +} From 9240db03b08975e2226b25ca387a29d07077ecfa Mon Sep 17 00:00:00 2001 From: Kaspars Zarinovs Date: Wed, 25 May 2022 01:30:50 +0300 Subject: [PATCH 2/3] Add Replace type --- src/types/global.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 513e617..6d2bd4e 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -16,4 +16,9 @@ declare global { * A slightly nicer way of defining nullable types. */ type Nullable = T | null; + + /** + * Replace keys of type with different types. + */ + type Replace = Omit & { [key in K]: R }; } From 871bdecfc872b2f6af1bc752b6d5c366dde99d7a Mon Sep 17 00:00:00 2001 From: Kaspars Zarinovs Date: Wed, 25 May 2022 01:33:19 +0300 Subject: [PATCH 3/3] Updated Replace type comments --- src/types/global.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 6d2bd4e..4a3191a 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -18,7 +18,7 @@ declare global { type Nullable = T | null; /** - * Replace keys of type with different types. + * Replace the type for specified keys of a type. */ type Replace = Omit & { [key in K]: R }; }