I have a function with an argument. This argument needs to be one of two kind of interfaces. So i write it like this:
add(item: IntDroga | IntSolucion){
if(item && item.identificacion){
if(item.estado.habilitada.value == false || item.estado.estado == estadoAprobacion.Aprobado){
// some code
}
}
}
But i recieve the following error.
Property 'habilitada' does not exist on type '{ estado: string; habilitada: { value: boolean; viewValue: string; }; excluida: boolean; } | { estado: estadoAprobacion; fecha: Date; usuario: string; }'.
Property 'habilitada' does not exist on type '{ estado: estadoAprobacion; fecha: Date; usuario: string; }'.ts(2339)
Here are the interfaces:
IntDroga:
export interface IntDroga {
_id: string;
identificacion: {
nombre: string,
codigo: string,
marca: string,
grupoSustancias: string,
nProducto: string,
lote: string,
CAS: string,
codigoAlternativo: string,
estandarInterno: boolean
};
informacion: {
pureza: number,
humedad: number,
fecha: {
fabricacion: Date,
recepcion: Date,
vencimientoCertificado: Date,
vencimientoAsignada: Date,
},
presentacion: string,
solucion?: { concentracion: number, unidad: string},
cantidad: {
recibida: {valor: number, unidad: string},
remanente: {valor: number, unidad: string},
unidad: string,
},
concentracion?: {valor: number, unidad: string},
DLDC: {
libre: {value: boolean, viewValue: string},
masaDL: number,
masaDC: number,
fDLDC: number,
};
sectores: string [];
rubros: string [];
ubicacion: string;
observaciones: string;
};
estado: {
estado: string,
habilitada: {value: boolean, viewValue: string},
excluida: boolean
};
}
IntSolucion:
export interface IntSolucion {
_id: string,
identificacion: {
nombre: string,
codigo: string,
},
informacion:{
tipo: string,
componentes: Componente [] ,
fecha:{
preparacion: Date,
vencimiento: Date,
descarte: Date
},
material:{
matraz: {
codigo: string,
volumen: {value: number, unidad: string}
}
},
temperaturaPreparacion: string,
almacenamiento: string
analista: string,
solvente: {tipo: string, identificacion: string}
},
estado?: {estado:estadoAprobacion, fecha: Date, usuario: string};
};
I can´t undestand what´s the problems. It is supposed that the function´s argument can have two different structures. I don´t know why Tslink marks it.
Thank you in advance for your help.