-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Added recursive check for nested tuple elements #43567
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
I think the spirit of the check was never really to dive deep into spreads. If you hit a spread, you probably want to just bail out from the check on that individual member, regardless of whether you have a tuple as the direct child. I'd check with others to see if that's the case. |
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 was imagining this would happen during createNormalizedTupleType
, which I think would let you avoid recursion, and would also ensure this works:
declare const point2d: [x: 1, y: 2];
declare const point3d: [...typeof point2d, z: 3]; // should be ok
But it may also be the case that this is harder than it sounds, and the correct answer for now is it’s not worth fixing. But I think worth trying is an approach like this:
- In
checkTupleType
instead of the recursive check, simply ignore any spreads. - In
createNormalizedTupleType
,expandedDeclarations
tracks whether any of the tuple elements have labels. When it’s an empty array, we don’t know yet. When it’s non-empty, at least one member had a label, so we assume that all do. When it’s undefined, at least one member lacked a label, so we assume that all do. InaddElement
,expandedDeclarations
gets silently mutated toundefined
in that latter case. If it ever goes from non-empty to undefined, or if it’s ever undefined anddeclaration
is defined, we have an inconsistency that can be reported oncurrentNode
(or ondeclaration
, or on the lastdeclaration
that was defined).
I've been checking Currently we get that information for the nested tuple, but for the other parameter we just have a type On the other hand ignoring the spread is super easy to achieve. I'm guessing the concerns on the recursion is due to performance. If you feel is worth it, instead of recursion I can just check one level deep and ignore any rests' if found after that. Let me know what you think. |
It looks like a small change will be necessary to
Not really, it’s that the example I gave in my last comment wouldn’t work. You can’t determine that |
As discussed this issue is invalid as the syntax is by design. |
Fixes #43516
Due to how the checker works, this algorithm will recursively check any nested tuples multiple times. I didn't found yet a way to reduce this unnecessary work. I'm open to ideas.