Closed
Description
TypeScript Version: 3.1.0-dev.20180801
Search Terms: overload, infer, function heads, tuple, rest parameter
Code
interface Foo {
(a: string, b: number, c: boolean): void;
(a: number, b: string, c: boolean): void;
}
type Args<F> = F extends (...args: infer T) => any ? T : never;
let x: Args<Foo> = [42, 'hello world', true]; // ✅
x = ['hello world', 42, true]; // 💥
Expected behavior:
Ideally, I would hope for the typeof x
to be
let x: [string, number, boolean] | [number, string, boolean]
although not entirely correct, I would even take a type wide enough to accomodate both function heads.
let x: [string|number, number|string, boolean]
Actual behavior:
The type of x ends up being
let x: [number, string, boolean]