2
I am having a problem checking if a variable is Undefined in the following typescript code.
Atendimento:any;
this.Atendimento.Checkout.Observacao == undefined ? '' : this.Atendimento.Checkout.Observacao;
If the Call does not return anything from the webservice, therefore setting the Call to Undefined, the following code gives error saying that the variable this.Atendimento.Checkout.Note is Undefined, ignoring the if, someone would know how to solve(Without having to declare a model class, because doing so would be a hassle in the system) and why this problem occurs?
Is there any way to check this in an if?
– Pedro Teixeira
Peter using Any in Typescript on many occasions is considered a bad practice, just as in this case you have an object that contains another object that contains some properties, the ideal would be to have all nodes typed to avoid the feared Undefined and not have to stay making If knot by knot as in the example of our friend Rodrigo.
– viniciusxyz
If I’m not mistaken, it’s possible to use something like
this.?Atendimento.Checkout.Observacao
but I can’t remember how it works– Costamilam