Skip to content

Can't call array methods on type (A[] | B[]) #18602

Closed
@testerez

Description

@testerez

TypeScript Version: 2.5.2

Code

function test(items: string[] | number[]) {
  items.forEach(item => console.log(item));
}

Expected behavior:
no error

Actual behavior:

Cannot invoke an expression whose type lacks a call signature. Type '((callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any) => void) | ...' has no compatible call signatures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions