SamJackSon SamJackSon - 1 year ago 90
TypeScript Question

TypeScript build error when assigning double dimensional array in VS2015

I am getting build errors in typescript project in VS2015. The application works fine in browser, but now I cannot publish due to these build errors.

export var AddedFields: Array<Array<Field>[]>[];

myGlobals.AddedFields[1][1] = new Field(, newField.label, newField.type, 0, 0);

Error is

Error TS2322 Build:Type 'Field' is not assignable to type 'Field[][]'. \Projects\angular2-systemjs-dotnet-core-master\src\TestAngular2\wwwroot\app\components\form-layout.component.ts 40 Build

Could someone please identify what am I doing wrong?

Answer Source

Both the Array and [] notations can indeed be used to define an array type in Typescript, but by using both at the same time, you have effectively declared a 4-dimensional array.

If you stick to one type of notation, it should be, for the Array notation:

export var AddedFields: Array<Array<Field>>;

or for the [] notation:

export var AddedFields: Field[][];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download