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

Improve error reporting for union member types #2472

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Cito
Copy link
Member

@Cito Cito commented Mar 4, 2020

First make sure that the included type is an object type, because that would be the more severe problem. Only then we can be sure that the type has a name and check for duplicates. Also, create only one error per different non-object type.

@@ -438,7 +438,20 @@ function validateUnionMembers(
}

const includedTypeNames = Object.create(null);
const includedInvalidTypes = Object.create(null);
Copy link
Member

@IvanGoncharov IvanGoncharov Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it strange behavior where after fixing one error you would get the same error in the next location.
We should definitely prevent implicit cascading errors but I think we should never mask explicit errors made by the user.
Also if we add this error reduction trick we need to add it in many other places (e.g. if you implement non-interface types) for consistency.

So I think moving check to the beginning of the loop and adding continue would be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this does not hide any errors - there is only one message, but all locations are reported and the same message applies to them all.

Base automatically changed from master to main January 27, 2021 11:10
@IvanGoncharov IvanGoncharov added this to the post-16.0.0 milestone Aug 23, 2021
@yaacovCR yaacovCR requested a review from a team as a code owner September 30, 2024 13:57
Copy link

netlify bot commented Sep 30, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit d390b94
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/66fab0103790eb00087500dc
😎 Deploy Preview https://deploy-preview-2472--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yaacovCR
Copy link
Contributor

@Cito I went ahead and rebased against main.

Copy link
Contributor

@yaacovCR yaacovCR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea, left some comments/questions!

@@ -480,7 +480,20 @@ function validateUnionMembers(
}

const includedTypeNames = new Set<string>();
const includedInvalidTypes = new Set<string>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just changed this to a single Set, visitedTypeNames?

);
includedInvalidTypes.add(typeString);
}
continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reminds me of #4181 => what do you think about changing the error message string to something that references both errors, at least if there are repetitions?

'Something like Union type can only include unique Object types, ....'

What do you think?

First make sure that the included type is an object type,
because that would be the more severe problem. Only then we
can be sure that the type has a name and check for duplicates.
Also, create only one error per different non-object type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants