Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda