Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 231
Hongbo Miao Avatar asked Aug 30 '16 07:08

Hongbo Miao


1 Answers

Changing

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

to either of these

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

will solve the issue.

like image 144
Hongbo Miao Avatar answered Sep 22 '22 16:09

Hongbo Miao