Skip to content

Array#map() is not callable on type-guarded array #40463

Closed
@saschanaz

Description

@saschanaz

TypeScript Version: Version 4.1.0-dev.20200909

Search Terms: map not callable

Code

function foo<T>(o: T) {
  if (Array.isArray(o)) {
      o.map(() => {});
  }
}

Expected behavior: It should work as it does in 4.1.0-dev.20200908.

Actual behavior:

abc.ts:3:9 - error TS2349: This expression is not callable.
  Each member of the union type '(<U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]) | (<U>(callbackfn: (value: any, index: number, array: readonly any[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other.

3       o.map(() => {});
          ~~~


Found 1 error.

Playground Link: It somehow shows no error on playground. https://www.typescriptlang.org/play?ts=4.1.0-insiders.20200909#code/GYVwdgxgLglg9mABMOcA8AVAfACgA4CGATgQLYBciGAlIgN4CwAUIq4jMIjgIJEkCeAOhgBnXgPzEy1WoxZsFhEqUEArODDA4ARNuoBuZgoC+zY0A

Related Issues:

Metadata

Metadata

Assignees

Labels

Has ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions