-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Better assignability errors to never-producing vacuous intersections #37618
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
Conversation
…ets reduced to 'never'.
e30996e
to
9e73730
Compare
9e73730
to
13269b3
Compare
@@ -44,6 +47,11 @@ tests/cases/conformance/types/intersection/intersectionReduction.ts(81,1): error | |||
ab.kind; // Error | |||
~~~~ | |||
!!! error TS2339: Property 'kind' does not exist on type 'never'. | |||
!!! error TS2339: The type 'never' was reduced from the intersection 'A & B'. Each type of that intersection has properties that conflict, so values of that type can never exist. |
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.
You should probably search for and report the properties that conflict and their respective types, no? So the error is somewhat more actionable?
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.
Definitely seems doable, but only if the approach in this PR seems reasonable.
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 OK. We could probably consider leaving behind more "breadcrumbs" like this in the future to explain how a specific type came about; but it's always about striking that balance between useful explaianation and terseness.
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.
Error seems good, and implementation seems OK except for the flags problem.
@@ -5653,5 +5653,9 @@ | |||
"An optional chain cannot contain private identifiers.": { | |||
"category": "Error", | |||
"code": 18030 | |||
}, | |||
"The type 'never' was reduced from the intersection '{0}'. Each type of that intersection has properties that conflict, so values of that type can never exist.": { |
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.
why 'each' here? Wouldn't 'some' be correct?
If that's true, I'd just say "Types in that intersection ..."
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.
Good point
#37618 provides the better error message. |
This was a naive first pass at something that I realized would be nice as I wrote up the breaking change section.
I couldn't do a fix everywhere because it became pretty impractical - for example, by the time we do the checks in some places, assignability, I guess we're given
never
instead of the original intersection.Things I'd like some guidance on:
1 << 29
onNodeBuilderFlags
. I've forgotten if that means I get a prize or a scolding for hitting the max unboxed value on a flag. (thanks @yuit)