I have an object whith an array and inside this a second array, just like this.
export class OrdenCompra {
public id?: number,
public insumos?: OrdenCompraInsumo[],
}
export class OrdenCompraInsumo {
id?: number;
traslados?: IImpuestoTraslado[];
}
export class ImpuestoTraslado{
public id?: number,
public impuesto?: number
}
i want to add some value to
traslados
like this
const retencion = new ImpuestoRetencion();
ordenCompra?.insumos[index]?.retenciones?.push(retencion);
but at this point
ordenCompra?.insumos[index]?.retenciones?
it is
undefined
so the value it is never assigned.
if i try to initialize i get an error.
ordenCompra?.insumos[index]?.retenciones = []
or
ordenCompra?.insumos[index]?.retenciones = ImpuestoRetencion[];
or
ordenCompra?.insumos[index]?.retenciones: ImpuestoRetencion[] || [];
which says
The left-hand side of an assignment expression may not be an optional property access.
so i have not been able to assign a value to this array. i know this is a very trivial question but even when i have search for hours.