Skip to content

Explicitly returning null in .map() #12

Description

@benadamstyles

I am using maybe in React Native, in the props of a custom text component. The custom component should set the underlying Text component prop numberOfLines to 1 by default, or null if the user passes false into the custom component's truncate prop:

<BasicText
  numberOfLines={maybe(props.truncate)
    .filter(t => !t)
    .map(() => null)
    .orJust(1)}
/>

However, flow understandably complains about returning null in .map():

null (This type is incompatible with union: number | boolean | string | object type | array type
See also: call of method `map`

Is there an "idiomatic" way to handle this, or is it simply a case of putting an // $ExpectError comment and forgetting about it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions