Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update nodes.ts to allow strong NodeType #4665

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

fezproof
Copy link

Changes

Issue: NodeType in NodeBase always resolves to be potentially undefined.

Solution: Update the NodeBase type to have a stronger NodeType field that can be undefined only if you don't specify it.

Use case

Current behaviour
image

Desired behaviour
image

This also now works for union types:
image

Version info

I consider this type issue a bug, but you probably want to link it to a minor version update to not shock people if the type suddenly change. Up to you though :)

Update the NodeBase type to have a stronger NodeType field that can be undefined even if you specifically define it.
Copy link

changeset-bot bot commented Sep 17, 2024

⚠️ No Changeset found

Latest commit: 37e9f02

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@moklick
Copy link
Member

moklick commented Sep 17, 2024

Hey @fezproof thanks for your input here. Why did you close the PR?

@fezproof fezproof reopened this Sep 17, 2024
@fezproof
Copy link
Author

Hey @fezproof thanks for your input here. Why did you close the PR?

Sorry didn’t mean to!

@bcakmakoglu
Copy link
Contributor

My 2 cents: this change would mean that user could not omit type anymore (which probably isn't a big deal for most users) to use the default node type without explicitly defining it as default.

For example:

    { id: 'a', type: 'input', position: { x: 0, y: 0 }, data: { label: 'wire' } }, // <--- this node is fine
    { id: 'b', position: { x: -100, y: 100 }, data: { label: 'drag me!' }, }, // <--- this node gives an error because `type` property is missing

@moklick
Copy link
Member

moklick commented Sep 17, 2024

I checked this again and unfortunately we can't make this change because it would be a breaking change. In a lot of examples (and real world apps), nodes do not have a type and all those apps would break.

@fezproof
Copy link
Author

Let me have another crack at this, I am sure I can get this to work

… ones

Updated svelte and react packages to accommodate this
@fezproof
Copy link
Author

@moklick @bcakmakoglu I have taken a second pass at this and updated the generic to be able to handle both defined and undefined NodeType. If undefined, it will fall back to the original definition.
All the repo now pass typechecks + it builds and passes tests.

@fezproof
Copy link
Author

Hey @moklick and @bcakmakoglu, does those changes fix your concerns?

@peterkogo
Copy link
Member

@fezproof Can you please explain what undefined extends NodeType really does? Or do you have some pointer to the official documentation.

@RichSchulz
Copy link
Contributor

RichSchulz commented Oct 11, 2024

@fezproof Can you please explain what undefined extends NodeType really does? Or do you have some pointer to the official documentation.

The way I understand this it checks whether the type provided as NodeType is undefined (i.e. no type provided) or can be undefined (e.g. "input" | "output" | undefined), and then propagates this information correctly to the type property of the NodeBase type (be either making it optional or not).

@fezproof is this what you intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants