11
votes

I am using Angular 2 with TypeScript 2.

When I use

let labels: string[] | number[] = [];
// let labels: Array<number> | Array<string> = [];

labels.push(1);

it gives me error:

error TS2349: Cannot invoke an expression whose type lacks a call signature.

1

1 Answers

28
votes

Changing

let labels: string[] | number[] = [];

to either of these

let labels: (string | number)[] = [];
let labels: Array<number|string> = [];

will solve the issue.