Skip to content

Extract array-parameter has wrong type error catching #26302

@Krakabek

Description

@Krakabek

TypeScript Version: 3.1.0-dev.201xxxxx

Search Terms:
Array spread types
Spread args array
spread generic types

Code
function call was found on msdn blog
I tried to call it with wrong arguments and get an error, but found a case that is not treated as an error, but it should.

function call<TS extends any[], R>(fn: (...args: TS) => R, ...args: TS): R {
    return fn(...args);
}

function test(a: number[]) {
}

call(test, [1, 2]); // this is ok
call(test, ["foo", "bar"]); // this has type error and is ok
call(test, ["foo", 1]); // this is treated as valid but is not

Expected behavior:
Both 2nd and 3rd calls should cause error

Actual behavior:
Only 2nd call is wrong, adding at least one number to array of strings makes this legit arg for function call

Playground Link:
Demo

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions