Creating an interface with an array of variable length, containing objects in TypeScript/Angular4

angular, arrays, interface, json, typescript

Solution

You should be using them as interfaces as below

export interface MyHomeBrewery {
    taps: Array<Taps>;    
    barrels: Array<Barrels>;
}

export interface Taps {

    id: number;
    name: string;
    type: string;
    quantity: number;
}

export interface Barrels {
    id : number;
    name: string;
    width: number;
    height: number;
    quantity: number;
}

Problem

I am attempting to create a variable within an in-memory database that contains a TypeScript interface that describes a JSON dataset. This dataset should contain multiple arrays, which in turn contain multiple objects with a fixed length and consistent attributes. I am writing this in Angular4 and TypeScript. The arrays must be of variable length with a minimum of 1 member I've written this pseudo code to show you what I mean: ``` export class MyHomeBrewery { taps: Array<any> = [{ id: number; name: string; type: string; quantity: number; }][...]; barrels: Array<any> { id: number; name: string; width: number; height: number; quantity: number; }][...]; ``` I've had a look through the TypeScript and Angular documentation and done a few searches and I can't find the correct syntax for this. Does anyone know?

Original source