Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!