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

264
Views
Error -::Type 'string | Element' is not assignable to type 'string'.?

I am using dangerouslySetInnerHTML in my React application (TypeScript based).

I am using it like this:

 <div dangerouslySetInnerHTML={{ __html:  faq.answer  }}/>

I am getting this error:

Type 'string | Element' is not assignable to type 'string'.

enter image description here

is there any way to fix this?

I am getting HTML from server like this <p>hello</p>. My output is correct. But while creating build my build breaks because we are doing typechecking before build.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You haven't provided much detail, but, assuming you want to serialize faq.answer in the case that it's an element, you can use Element.outerHTML like this:

<div dangerouslySetInnerHTML={{ __html: typeof faq.answer === 'string'
  ? faq.answer
  : faq.answer.outerHTML }}/>
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!