Propose to make node data NOT optional
See original GitHub issueThe current data type for Node is
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.
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:
- Created 2 years ago
- Reactions:5
- Comments:9 (3 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
Good point. I think we should make
data
of an Edge non-optional, too.@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 assumedata
is optional, even if I’m enforcing it to not be from the outside