Skip to content

TS ^4 does not recognize array methods on (T[] | T[][]) as callable #40157

Closed
@dkamyshov

Description

@dkamyshov

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.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions