-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
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 notExpected 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code