-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add RequiredPick and RequiredExcept (#9)
- Loading branch information
Showing
4 changed files
with
19 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
// Thanks [jack-williams](https://github.com/jack-williams) for the [solution](https://github.com/Microsoft/TypeScript/issues/29269#issuecomment-451602962) | ||
|
||
export type RequiredPick<T, U extends keyof T> = { | ||
[P in keyof T]: T[P] extends undefined ? never : T[P] | ||
} | ||
[P in U]-?: Exclude<T[P], undefined> | ||
} & Pick<T, Exclude<keyof T, U>> | ||
|
||
export type RequiredExcept<T, U extends keyof T> = { | ||
[P in keyof T]: P extends U ? T[P] : Exclude<T[P], undefined> | ||
} | ||
[P in Exclude<keyof T, U>]-?: Exclude<T[P], undefined> | ||
} & Pick<T, U> |
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