Skip to content

Error when variadic elements generated by generic type and other value make an array #52354

Closed

Description

@kermanx

Bug Report

🔎 Search Terms

  • generic type
  • variadic elements
  • array

🕗 Version & Regression Information

  • This is the behavior in every version I tried (including v4,Nightly)(in v3 everything errors), and I reviewed the FAQ for entries about "Generics"

⏯ Playground Link

Playground link with relevant code

💻 Code

class I<SS extends string>{
    f() {
        let x: [ //Errors when SS is generic and `t` exists
            t: "AAA",
            ...args: {
                [S in SS]: [a: number];
            }[SS]
        ] = ["AAA", 1];

        type SS1 = string;
        let y: [ // OK when SS1 is not generic
            t: "AAA",
            ...args: {
                [S in SS1]: [a: number];
            }[SS1]
        ] = ["AAA", 1];

        type SS2 = "1" | "2" | "3";
        let z: [ // OK when SS2 is not generic
            t: "AAA",
            ...args: {
                [S in SS2]: [a: number];
            }[SS2]
        ] = ["AAA", 1];

        let w: [ // OK when `t` doesn't exist!!!
            ...args: {
                [S in SS]: [a: number];
            }[SS]
        ] = [1];
    }
}

🙁 Actual behavior

x errors, but w doesn't
x errors, but y and z doesn't

🙂 Expected behavior

x shouldn't be a error.

Activity

  1. kermanx commented on Jan 22, 2023

    @kermanx
    Author

    Also, when SS defined in f insteadof I, the error still happends.

  2. kermanx commented on Jan 22, 2023

    @kermanx
    Author

    The error message is:

    Type '["AAA", 1]' is not assignable to type '[t: "AAA", ...args: { [S in SS]: [a: number]; }[SS]]'.
      Source provides no match for variadic element at position 1 in target.
    
  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

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions