oportunidad.model.ts:
const enum TipoSiNo {
SI, NO
}
export class Oportunidad {
constructor(
public resultadoValidacion?: TipoSiNo,
I need to buy the value of my object with one of the possible values of the enumerated:
oportunidad-edit.component.ts:
add:
const enum TipoSiNo {
SI, NO
}
this.oportunidad.resultadoValidacion === TipoSiNo.NO
Give me the following error
ERROR in [at-loader] ./src/main/webapp/app/entities/oportunidad/oportunidad-edit.component.ts:337:75
TS2365: Operator '===' cannot be applied to types 'TipoSiNo.NO' and 'TipoSiNo.NO'.
I can see you are creating the same enum: TipoSiNo at two different places and hence both are two different types so the comparison is not going to work.
I came here to find why I can't compare the two enum values from the same enum, but couldn't really get any answer anywhere. Example:
export enum Stage{
NotStarted, QuarterOf, Half, QuarterTo, Full
}
export class Work{
id: number,
title: string,
description: string,
status: Stage
}
// check if work is not started
if(this.currentWork===Stage.NotStarted){ // <- this is never true
// do something
}
So, I found a workaround:
// check if work is not started
if(this.currentWork.toString===Stage[Stage.NotStarted]){ // <- this works
// do something
}
Hopefully, it helps someone
Try this:
this.oportunidad.resultadoValidacion as TipoSiNo === TipoSiNo.NO as TipoSiNo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With