Skip to content

Instantly share code, notes, and snippets.

@apiv
Last active November 1, 2017 03:31
Show Gist options
  • Save apiv/8083676e2335f456e19b34d06e60d5d9 to your computer and use it in GitHub Desktop.
Save apiv/8083676e2335f456e19b34d06e60d5d9 to your computer and use it in GitHub Desktop.
// @flow
type Options = {
getId: (passedProps: {}) => string | string[]
}
const Entities = (options: Options) => /* ...code ... */
Entities({ getId: ({ contactId }) => Immutable.List([contactId]) })
// => throws a compiler error, return type of getId must be string | string[]
Entities({ getId: ({ contactId }) => contactId && [contactId] })
// => throws a compiler error, contactId might be undefined, since it is not typed
Entities({ getId: ({ contactId }) => [contactId] })
// => all good, compiler compiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment