Assign an empty array to an object which implements interface and push new objects into it later on

Viewed 302

I have the following interface:

export interface FacilityInformation
{
  facilitiesInformation: [
  {
    id: string,
    productType: string,
    productSubtype: string,
    nominalAmount: number,
    currency: string,
    maturity: string,
    fee: number,
    recommended: number,
    margin: number,
    roac: number,
    ep: number
  }
 ],
 allFacilities: {
  amount: number,
  fee: number,
  roac: number,
  ep: number
 },
 customerLevel: {
  amount: number,
  fee: number,
  roac: number,
  ep: number
 },
 groupLevel: {
  amount: number,
  fee: number,
  roac: number,
  ep: number
 }
}

My goal is to initialize an empty object which implements interface FacilityInformation with an EMPTY array facilitiesInformation and later push objects into this array. However, I can't seem to be able to initialize an empty array, it asks me to assign values straight away:

let facilityInformation : FacilityInformation = 
{
  facilitiesInformation :   
  { id: string, productType: string ... } [], // says string is a type but used as a value

After assigning an empty array I would like to do this:

  facilityInformation.facilitiesInformation.push({...})

How can I first if all initialize an empty array and then push objects into it?

1 Answers

Use this way.

let facilityInformation: FacilityInformation = 
{
  facilitiesInformation: [] as any,
  ...
} as FacilityInformation;
Related