If I have the following type:
type MyType = {
a: ?any;
b: ?any;
}
And the following instance of it:
var myThing : MyType = {
a: 'hello'
};
Flow will find the following error:
/Users/tboyt/Coding/mode7/src/Foo.js:2:15,5:1: property b
Property not found in
/Users/tboyt/Coding/mode7/src/Foo.js:7:24,9:1: object literal
This makes sense, given that the maybe type is intended to be either the given type or null, not the type or undefined. However, not being able to define a property as entirely optional - e.g., being either a specific type or undefined - seems like a big missing feature.
For an example use case, imagine an API with a constructor that uses a hash of keyword arguments, most of which are optional. It would be great to be able to enforce the types of those arguments, if present, using Flow, and ignore missing arguments.
If I have the following type:
And the following instance of it:
Flow will find the following error:
This makes sense, given that the maybe type is intended to be either the given type or
null, not the type orundefined. However, not being able to define a property as entirely optional - e.g., being either a specific type orundefined- seems like a big missing feature.For an example use case, imagine an API with a constructor that uses a hash of keyword arguments, most of which are optional. It would be great to be able to enforce the types of those arguments, if present, using Flow, and ignore missing arguments.