Reputation:
I constantly run into the same issue with flow: I annotate something as ?type
and forget that that accepts null
so when I do something like this:
function foo(data: string = '') {}
function bar(data: ?string) { foo(data); }
flow yells at me because foo(null)
doesn't resolve data
to a string
, but foo(undefined)
does. So is there a simpler way to write this:
function bar(data: string|typeof undefined) {
Or am I doing something fundamentally wrong?
Upvotes: 0
Views: 408
Reputation: 37338
typeof undefined
is void
in flow.
So what about:
function bar(data: string | void | null) {
or
function bar(data?: string | null) {
Upvotes: 2