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

Allowed tuples to have both named and anonymous members #53356

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

Conversation

JoshuaKGoldberg
Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Mar 19, 2023

Fixes #52853

Previously, the labeledElementDeclarations property on TupleTypes was all-or-nothing for having named vs. anonymous members. Now that it's possible for them to mix-and-match, this PR pulls logic from getParameterNameAtPosition into getTupleElementLabel for filling in a name (`${restParameterName}_${index}`).

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Mar 19, 2023
@@ -6399,7 +6399,7 @@ export interface TupleType extends GenericType {
hasRestElement: boolean;
combinedFlags: ElementFlags;
readonly: boolean;
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration | undefined)[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[Breaking API Change] Is this the right choice to make? One alternative could be to rename it to elementDeclarations with a type like readonly (ParameterDeclaration | TypeNode). My hunch is that that would be preferable, but I'm going with this smaller change for now to make reviewing easier.

JoshuaKGoldberg and others added 2 commits March 23, 2023 12:09
Co-authored-by: Jake Bailey <jabaile@microsoft.com>
@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review March 23, 2023 16:48
Co-authored-by: Jake Bailey <jabaile@microsoft.com>
@JoshuaKGoldberg JoshuaKGoldberg requested review from jakebailey and Andarist and removed request for jakebailey March 24, 2023 12:14
@Andarist
Copy link
Contributor

I think that it would be nice to get some code coverage for generic mapped types with array constraints. With them named and anonymous elements should be preserved in the same way. Similarly, it should be possible to add new named/anonymous elements using generic conditional types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Labeled variadic tuples should not require labeling spreads for tuples that are already labeled
4 participants