Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
Is there a way to always use Optional-chaining in Angular

I am working with an Angular app where the api response can be missing some expected data.

This can crash the app and an easy fix has been to use Optional-chaining;

foo.bar.baz => foo.bar?.baz

Is there a setting or way to treat all '.' as '?.' and would this be a bad idea for any reason?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As far as i went through the official Angular & Typescript docs, There is no such option. And there shouldn't be.

Its definitely a bad idea. This will result in "Silent" bugs, that will be hard to find as the system grows.

e.g. if you have the following model:

interface ContactInfoDTO {
   email: string;
   phone: string;
}

interface UserDTO {
   name: string;
   contactInfo: ContactInfoDTO;
}

And you assume that every user in the system should have a valid contact info. When you access the email property user?.contactInfo?.email, you could end up with a bug, not knowing that something is actually wrong with your data, since no error was thrown.

Use Optional-chaining carefully, only where you know that some data might not be defined for a reason.

There is a nice article on the matter: https://medium.com/@a.hafez852/is-optional-chaining-really-a-good-addition-to-javascript-e4bbbc31909f

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda