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

187
Vistas
getting type error when I try to assign interface to a property

I'm using typescript in my Angular project trying to assign IInfoPage interface to data

    export interface IInfoPage {
      href: string;
      icon: string;
      routing: boolean;
      order: number;
      styleType: string;
    }

    public pageData: IInfoPage;


    this.configService.PageData.subscribe((res) => {
        this.pageData = res.SubMenu.find(data => location.pathname.includes('path'));
    })

But as I see this.pageData alerts and gives me this error:

Type 'ISubMenuType | undefined' is not assignable to type 'IInfoPageSubData'.   Type 'undefined' is not assignable to type 'IInfoPageSubData'.

So How can I solve this issue?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Array.find() can always return undefined, so you'll need to check whether or not find has returned a result.

const result = res.SubMenu.find(data => location.pathname.includes('path'));

if(result)
  this.pageData = result;
about 4 years ago · Santiago Gelvez 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