TypeScript Version: 4.0.2, 4.1.0-dev.20200820
Search Terms: union, array methods
Code
The following example uses every method, but the bug affects all other methods as well (map, reduce, etc.).
const a: string[] | string[][] = [];
a.every(b => console.log(b)); // TS-2349: This expression is not callable.
// Attempt №1: suppress TS-7006
a.every((b: string | string[]) => console.log(b)); // TS-2349: This expression is not callable.
// Attempt №2: rewrite as typeguard (as in https://github.com/microsoft/TypeScript/blob/v4.0-beta/lib/lib.es5.d.ts#L1319)
a.every((b: string | string[]): b is string => typeof b === 'string'); // TS-2349: This expression is not callable.
Expected behavior: No errors, code should compile.
Actual behavior: Error TS-2349: This expression is not callable.
Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20200819#code/MYewdgzgLgBAhgLhtATgSzAcwNoF0YA+yU6WeeMAvDHgNwBQ9cAdAKYBurKAngBQBGVAHwxQkEABtWzCSEwCAlAoZM2nHrwFJUGTIWKkcuBcNHgIk6bPn8lKlhy58tB3fp1ljSQWgiusplDcAA6sIABmMIKUMTAA5B6Yccr0QA
Related Issues: I didn't find anything similar.
TypeScript Version: 4.0.2, 4.1.0-dev.20200820
Search Terms: union, array methods
Code
The following example uses
everymethod, but the bug affects all other methods as well (map,reduce, etc.).Expected behavior: No errors, code should compile.
Actual behavior: Error
TS-2349: This expression is not callable.Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-dev.20200819#code/MYewdgzgLgBAhgLhtATgSzAcwNoF0YA+yU6WeeMAvDHgNwBQ9cAdAKYBurKAngBQBGVAHwxQkEABtWzCSEwCAlAoZM2nHrwFJUGTIWKkcuBcNHgIk6bPn8lKlhy58tB3fp1ljSQWgiusplDcAA6sIABmMIKUMTAA5B6Yccr0QA
Related Issues: I didn't find anything similar.