Last active
June 26, 2021 03:36
-
-
Save GiuseppeMP/d2ef020ced09447de4b4f89fa7516986 to your computer and use it in GitHub Desktop.
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
+ or - allows control over the mapped type modifier (? or readonly). -? means must be all present, aka it removes optionality (?) e.g.: | |
type T = { | |
a: string | |
b?: string | |
} | |
// Note b is optional | |
const sameAsT: { [K in keyof T]: string } = { | |
a: 'asdf', // a is required | |
} | |
// Note a became optional | |
const canBeNotPresent: { [K in keyof T]?: string } = { | |
} | |
// Note b became required | |
const mustBePreset: { [K in keyof T]-?: string } = { | |
a: 'asdf', | |
b: 'asdf' // b became required | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment