question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nullable and optional properties

See original GitHub issue

This 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:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
samhagancommented, Aug 30, 2017

@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.

1reaction
samhagancommented, Aug 30, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found