Closed
Description
TypeScript Version: 4.1.0-dev.20201011
Search Terms: rest parameters, type inference
Expected behavior: All test cases are valid ones.
Actual behavior: cases t3
and t4
are correctly understood by the TS compiler, the other ones result in errors:
Argument of type 'number' is not assignable to parameter of type 'string'.
Argument of type '"b"' is not assignable to parameter of type '"a"'.
Related Issues: #37193
Code
declare function f1<T>(...list: ReadonlyArray<T>): T;
declare function f2<T>(...list: T[]): T;
declare function f3<T>(list: T[]): T;
const s:string = "str";
const ar = ["a", "b", "c", 0];
const t1 = f1(s, "a", "b", 0);
const t2 = f2("a", "b", "c", 0);
const t3 = f3(["a", "b", "c", 0]);
const t4 = f1(...ar);
Output
"use strict";
const s = "str";
const ar = ["a", "b", "c", 0];
const t1 = f1(s, "a", "b", 0);
const t2 = f2("a", "b", "c", 0);
const t3 = f3(["a", "b", "c", 0]);
const t4 = f1(...ar);
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided