Created
July 31, 2020 12:00
-
-
Save corocoto/cc7804ff2c8a2d92f8eca1948f7ba0c2 to your computer and use it in GitHub Desktop.
Flow | Maybe type defining
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
| /** | |
| * `Maybe` type allows us to type annotate a potentially `null` or `undefined` value. | |
| * They have the type `T|void|null` for some type `T`, meaning it is either type `T` or it is `undefined` or `null`. | |
| */ | |
| var message: ?string = null; //here I’m saying that message is either a `string`, or it’s `null` or `undefined` | |
| /** | |
| * You can also use maybe to indicate that an object property will be either of some type `T` or `undefined`. | |
| * | |
| * By putting the `?` next to the property name for `middleInitial`, you can indicate that this field is optional. | |
| */ | |
| type Person = { | |
| firstName: string, | |
| middleInitial?: string, | |
| lastName: string, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment