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

121
Views
How to solve multi type object data in single parameter

I declare this to receive options params value where value can be a single string or another object like options?: string[] | IServiceDetail[] | IServiceAccordion[];

But when I am trying to map the above objects getting an error:

Property 'title' does not exist on type 'string | IServiceAccordion | IServiceDetail'.
  Property 'title' does not exist on type 'string'.

Screenshot

return options?.map(
                  (category: string | IServiceDetail | IServiceAccordion) => {
                    return (
                      <Text
                        key={category.title}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can check if the type is not a string before accessing the title, because a string is a primitive and does not have any property:

   options?.map((category: string | IServiceDetail | IServiceAccordion) => { 
     if(typeof category !== "string") return <Text key={category.title} />
     else return return <Text key={category} />
   }
about 4 years ago · Juan Pablo Isaza Report

0

because string is a premitive type. so doesn't have "title" attribute. if you are sure that category is not string and is object and also has "title" attribute, you can use type casting

<Text
  key={(category as IServerDetail).title}
/>
about 4 years ago · Juan Pablo Isaza 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!