Nullable and optional properties
See original GitHub issueThis is a:
- Bug Report
- Feature Request
- Question
- Other
Which concerns:
- flow-runtime
- babel-plugin-flow-runtime
- flow-runtime-validators
- flow-runtime-mobx
- flow-config-parser
- The documentation website
What is the current behaviour?
Making a property of a type nullable behaves the same as if it was optional.
const A = t.type("A", t.object(t.property("a", t.nullable(t.boolean()))));
const B = t.type("B", t.object(t.property("a", t.boolean(), true)));
A.assert({}); // passes
B.assert({}); // passes
What is the expected behaviour?
I was expecting that a nullable property has to be set, but accepts null values, and optional properties may be omitted.
A.assert({a: null}); // passes
A.assert({a: undefined}; // passes
A.assert({}); // fails (property "a" does not exist)
Which package versions are you using?
I used the live demo: https://codemix.github.io/flow-runtime
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Can an optional property value be null? - typescript
An optional property means that the property may either be of the type on the right (here, string ), or it may be...
Read more >Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >Defining Optional Properties and Nullable Values in RAML
Defining optional properties and nullable values in RAML is vital for a smooth integration experience. Here's how to do it.
Read more >Making optional properties nullable in TypeScript - rbardini.com
Your types are defined with non-nullable optional properties (e.g., x?: number ), but the data coming from the API returns null instead.
Read more >Nullable types and optional parameters/properties (TypeScript)
An overview of how TypeScript deals with null, undefined and optional parameters/properties.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@fabiandev thanks for the quick reply. I hadn’t noticed that…this is happening to us on api boundaries, so the strictness just highlighted bad type definitions.
This change seems inconsistent with Flow, which allows { field: ?number } to be null, undefined/void, or a number, which means that it can also be omitted. This is preventing us from upgrading from 0.12.0 without some material type changes. Could we make this configurable via options? Happy to look at doing a PR.