Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created July 31, 2020 12:00
Show Gist options
  • Select an option

  • Save corocoto/cc7804ff2c8a2d92f8eca1948f7ba0c2 to your computer and use it in GitHub Desktop.

Select an option

Save corocoto/cc7804ff2c8a2d92f8eca1948f7ba0c2 to your computer and use it in GitHub Desktop.
Flow | Maybe type defining
/**
* `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