Closed
Description
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.
Related Issues: I didn't find anything similar.