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.

Propose to make node data NOT optional

See original GitHub issue

The current data type for Node is

image

This means even when you assign T such as Node<ElementData> and know in your program all Nodes would have T. it will still show the data as possibly being undefined.

image

Because T defaults to any which could be undefined.

Changing data?: T to data: T would still allow setting data: undefined on new element objects if needed.

Side note, I think the default renderer for nodes actually requires the data to be { label: 'string } so setting undefined on Nodes might crash application which means this is another reason it should not be typed as optional since it’s actually required.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
moklickcommented, Jun 7, 2022

Good point. I think we should make data of an Edge non-optional, too.

1reaction
tisoapcommented, Nov 19, 2021

@moklick On a project I faced an issue where nodes needed to have a certain data shape, but even if the external interface to my component consuming React Flow did make it required, I still had to do type casting since <ReactFlow> callbacks assume data is optional, even if I’m enforcing it to not be from the outside

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
Optional chaining cannot be used on a non-declared root object, but can be used with a root object with value undefined .
Read more >
How to use optional chaining in Node.js 12 - Stack Overflow
Optional chaining is currently not supported in Node.js version 13 and below. It will be supported from Node.js version 14 and most of...
Read more >
How to Use Optional Chaining in JavaScript - freeCodeCamp
In the chain of object property access we can check that each value is not undefined or null. This check can be extremely...
Read more >
Optional chaining '?.' - The Modern JavaScript Tutorial
The optional chaining ?. is a safe way to access nested object properties, even if an intermediate property doesn't exist.
Read more >
tc39/proposal-optional-chaining - GitHub
The following languages have a similar feature, but do not short-circuit the whole chain when it is longer than one element. This is...
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