-
Notifications
You must be signed in to change notification settings - Fork 2k
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
base: main
Are you sure you want to change the base?
Conversation
src/type/validate.js
Outdated
@@ -438,7 +438,20 @@ function validateUnionMembers( | |||
} | |||
|
|||
const includedTypeNames = Object.create(null); | |||
const includedInvalidTypes = Object.create(null); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
2ca0fda
to
3eba0c8
Compare
✅ Deploy Preview for compassionate-pike-271cb3 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@Cito I went ahead and rebased against main. |
There was a problem hiding this 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>(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
3eba0c8
to
d390b94
Compare
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.