Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 为实现接口的对象分配一个空数组,并在以后将新对象推入其中_Arrays_Typescript - Fatal编程技术网

Arrays 为实现接口的对象分配一个空数组,并在以后将新对象推入其中

Arrays 为实现接口的对象分配一个空数组,并在以后将新对象推入其中,arrays,typescript,Arrays,Typescript,我有以下界面: export interface FacilityInformation { facilitiesInformation: [ { id: string, productType: string, productSubtype: string, nominalAmount: number, currency: string, maturity: string, fee: number, recommended

我有以下界面:

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
 }
}
我的目标是初始化一个空对象,该对象使用空数组
facilitieinformation
实现接口
FacilityInformation
,然后将对象推入该数组。但是,我似乎无法初始化空数组,它要求我立即赋值:

let facilityInformation : FacilityInformation = 
{
  facilitiesInformation :   
  { id: string, productType: string ... } [], // says string is a type but used as a value
分配空数组后,我希望执行以下操作:

  facilityInformation.facilitiesInformation.push({...})
我如何首先初始化一个空数组,然后将对象推入其中?

使用这种方法

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

我收到一个错误:类型“[]”中缺少属性“0”,但类型“[{id:string,productType:string…”中需要属性“0”。我收到一个错误:属性设施信息的类型不兼容。请重试编辑的回答:请查看此stackblitz