Flow: This type is incompatible with null

Created on 6 Apr 2017  路  5Comments  路  Source: facebook/flow

Possible there is a simple solution, but clearly seems I missing something. Any ideas what prop type should I use here?

  state: { focusedInput: string }
  constructor(props: FilterProps) {
    super(props);
    this.state = {
      focusedInput: null
    }
  }

Most helpful comment

you probably want to use ?string ([maybe type]) to allow both null/undefined and string values as well.

All 5 comments

Ah, seems like using type null sort it out.

state: { focusedInput: null }

you probably want to use ?string ([maybe type]) to allow both null/undefined and string values as well.

@madbence Thanks for the suggestion!

can I have a ?string as a return type?

@sibelius sure, eg.:

function maybeString(): ?string {
  return null;
}
Was this page helpful?
0 / 5 - 0 ratings