镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

🔎 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

Activity

  1. Andarist commented on Mar 14, 2024

    @Andarist
    Contributor

    It works as intended as per the change in #57031

  2. typescript-bot commented on Mar 18, 2024

    @typescript-bot
    Contributor

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

  3. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions