Skip to content

Spread of two generic array types is misreported as having length 2Β #58697

@dragomirtitian

Description

@dragomirtitian

πŸ”Ž Search Terms

tuple spread any generic

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground Link

πŸ’» Code

function join<T extends any[], P extends any[]>(): [...T, ...P] {
    let x: any[] = [];
    return x; // Target requires 2 element(s) but source may have fewer βŒβ—β“
}

function join2<T extends any[], P extends any[]>(): [...T, ...P] {
    let x: [any, any] = null!
    return x; // Source provides no match for variadic element at position 0 in target βœ…
}

πŸ™ Actual behavior

join errors on return with Target requires 2 element. There is nothing in the target type that suggests it requires two elements.

πŸ™‚ Expected behavior

Should error with a message similar to join2:

Source provides no match for variadic element at position 0 in target

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions