-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
77 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
/** | ||
* Makes all keys in required and removes undefined and null from the value types. | ||
* Makes all keys required and removes undefined and null from the value types. | ||
* @example | ||
* type Example = { | ||
* a: string; | ||
* b: string | undefined; | ||
* c?: string; | ||
* d?: number | null; | ||
* }; | ||
* type Result = DefinedKeys<Example>; | ||
* type Result = Defined<Example>; | ||
* { | ||
* a: string, | ||
* b: string, | ||
* c: string, | ||
* d: number | ||
* } | ||
*/ | ||
export type DefinedKeys<T> = { | ||
export type Defined<T> = { | ||
[P in keyof T]-?: NonNullable<T[P]>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Defined } from "./Defined"; | ||
|
||
/** | ||
* Makes picked keys required and defined. | ||
* @example | ||
* type Example = { | ||
* a: string; | ||
* b: string | undefined; | ||
* c?: string; | ||
* d?: number | null; | ||
* }; | ||
* type Result = PickDefined<Example, "a" | "b" | "d">; | ||
* { | ||
* a: string; | ||
* b: string | undefined; | ||
* d: number | null; | ||
* } | ||
*/ | ||
export type PickDefined<T, K extends keyof T> = Pick<Defined<T>, K>; | ||
|
||
// Test | ||
// type Example = { | ||
// a: string; | ||
// b: string | undefined; | ||
// c?: string; | ||
// d?: number | null; | ||
// e: never; | ||
// }; | ||
|
||
// type Result = PickDefined<Example, "a" | "b" | "c" | "d" | "e">; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters