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

240
Views
Type 'string' is not assignable to type ' undefined'

I have one React Component in which I am using useState hook. I tried to set value to general onClick of menu item.

const [value,setValue]= useState("");

<Menu.Item onClick={()=>setValue("general"))>

</Menu.Item>

In another file I am passing that value.

<ChannelForm
   value={value}
/>

I am using TypeScript. Have declared prop type definition as

value?: "general" | "competitive" | "social" | "podcast";

But while passing value as a props I am getting above error.

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

0

Just to clarify - are you using an interface? See this question: Using state in react with TypeScript, for more on that.

If that doesn't help, the problem could be typescript thinks it's being passed a null value. To fix that you can use the non-null assertion operator. Read more about that in this answer: Typescript: Type 'string | undefined' is not assignable to type 'string'

If neither of those helps, let me know!

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!