Last active
January 11, 2021 13:52
-
-
Save jeromecovington/f46e6dea4b37622af078c9adef935231 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type PartiallyRequired<T, K extends keyof T> = Pick<T, K> & Partial<T>; | |
type Test = { | |
foo: string; | |
bar: string; | |
baz: string; | |
}; | |
type Test1 = PartiallyRequired<Test, "foo">; | |
// Will error if foo is not included. bar, baz optional. | |
const test1: Test1 = { | |
foo: '', | |
bar: '', | |
baz: '' | |
} | |
type Test2 = PartiallyRequired<Test, "bar" | "baz">; | |
// Both bar and baz must be included. foo optional. | |
const test2: Test2 = { | |
foo: '', | |
bar: '', | |
baz: '' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment