Skip to content

Unable to append a type to an existing tuple #31286

Closed
@Roaders

Description

@Roaders

TypeScript Version: 3.2.4

Search Terms:
Tuple, merge, combine

Code

function combine<T, U extends any[]>(item: T, items: U): [T, ...U] {
    return [] as any;
}
const result = combine("hello", ["goodbye", 123, true]);

Expected behavior:
result should be typed as [string, string, number, boolean].

Actual behavior:
Compile error:
A rest element type must be an array type.

Playground Link:
Link

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions