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

Key for rest Tuple argument missing when mapping tuple type #57770

Closed
trevorade opened this issue Mar 13, 2024 · 2 comments
Closed

Key for rest Tuple argument missing when mapping tuple type #57770

trevorade opened this issue Mar 13, 2024 · 2 comments
Labels
Not a Defect This behavior is one of several equally-correct options

Comments

@trevorade
Copy link

πŸ”Ž Search Terms

"tuple", "tuple type"

πŸ•— Version & Regression Information

  • This changed between versions 5.3.3 and 5.4.2

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.2#code/C4TwDgpgBA4hwBUCuYA2EDSEQGcA8ya0EAHsBAHYAmOUSFA1hQPYDuFA2gLoB8UAvFADeHDFACWFKA2zMAZlELouALigYAvhxkh5ilMoDcAKGMB6M1ACSUgKwA6ACz2ATFFbQA5vCgADCkgAtgBGEABOUAA+UABEAAwxvuaWNlAOAMz26e5ePv5BoRHR8TFRsQCMicZCoJBQ5DjAArDwSpjY+ByNYZKeADRQ9kMBIeHcvBrJUNNQAHoA-KYW1nZOrjlQ3k2+JWVuxZW+UAAUrAAW4gDGZxK0EACOSOIAbgCG6BRNrxQgrK+4AEopqkMlkNls-LsDqVoi4kjVwNAGk1BHBEAZ2rg8F1gD0KP0oCNChMpjMFsYgA

πŸ’» Code

type GetTupleKeys<Tuple extends unknown[]> = {[K in keyof Tuple]: K}[keyof Tuple];

// In 5.4.2 we get `number | "0"`
// In 5.3.3 we get `number | "0" | "1"`
{type test = GetTupleKeys<[string, ...number[]]>}
//    ^?

// In 5.4.2 we get `"0" | 2 | "1"` (which is equivalent anyways)
// In 5.3.3 we get `"0" | "1" | 2`
{type test = GetTupleKeys<[string, number]>}
//    ^?

πŸ™ Actual behavior

In 5.4.2, rest arguments in tuples no longer get a dedicated key/index when mapping the tuple type. In the above example, the tuple type [string, ...number[]] effectively produces the keys number | "0"

πŸ™‚ Expected behavior

No regression. The above example should be as 5.3.3 and resolve to the keys number | "0" | "1"

Additional information about the issue

This is specifically impacting the following code:
https://github.com/sindresorhus/type-fest/blob/main/source/set-parameter-type.d.ts#L7

As reported in:
sindresorhus/type-fest#831

@Andarist
Copy link
Contributor

It works as intended as per the change in #57031

@RyanCavanaugh RyanCavanaugh added the Not a Defect This behavior is one of several equally-correct options label Mar 15, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Defect This behavior is one of several equally-correct options
Projects
None yet
Development

No branches or pull requests

4 participants