Skip to content

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

Closed as not planned
@trevorade

Description

@trevorade

πŸ”Ž 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

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