Closed motiz88 closed 9 years ago
awesome, thanks!
It's sort of weird that there are so many ways to do the same thing with flow syntax, for function arguments I've been using:
function foo (str: ? string) {}
But I agree that
function foo (str?: string) {}
is much nicer, I wonder why it allows both.
Those are actually somewhat different. ?T
is a nullable or so-called maybe type - effectively shorthand for T | null | undefined
, whereas x?: T
is narrower to the effect of x: T | undefined
, omitting the null
.
This is what I was referring to as "my understanding of Flow's ... semantics", which incidentally I'm now more confident about, having read this. Some of the test cases I wrote verify this exact distinction (passing null in an optional param should fail, likewise in an optional property of an object-typed param).
The added functionality and tests reflect my understanding of Flow's optional properties and optional arguments semantics.
Optional arguments use the
x?: T
syntax that the Flow docs mention in passing.