Tampa Tampa - 1 year ago 205
TypeScript Question

angular2 and Typescript array - Property 'push' does not exist on type '() => void'

How do I init an empty array?

test: any[];

//On change I want to add an item to an array

error TS2339: Property 'push' does not exist on type '() => void'.

Answer Source

You don't initialize your array, so test is undefined. To be able to use it, just initialize it this way:

test: any[] = [];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download