question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setValue()'s first parameter is always of type 'never' in Typescript

See original GitHub issue

Describe the bug I try to use react-hook-form in Typescript. The IDE (IntelliJ in my case but also the Typescript compiler) complains that

Argument of type "..." is not assignable to parameter of type never

To Reproduce

Here’s a simple codesandbox project. Open it in the Editor, wait a bit and you will see that in line index.tsx:8 “someField” will be marked red and mouse over will show

Argument of type "someField" is not assignable to parameter of type never

https://codesandbox.io/embed/react-typescript-vf3xc

The same thing happens in IntelliJ as well.

If you mouse over on useForm in index.tsx:6 the second type argument there will also be ‘never’.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:24 (15 by maintainers)

github_iconTop GitHub Comments

7reactions
stramelcommented, Sep 7, 2019

@beepsoft Your codesandbox is giving errors about crossorigin errors. However, if you pass the generic to useForm it should not give you any errors. In your case, useForm<{ someField: string }>() should get rid of the error. It shouldn’t require the generic so I can look into that if you can provide a codesandbox that doesn’t trigger cors errors.

3reactions
stramelcommented, Sep 8, 2019

@bluebill1049 Yeah, we shouldn’t require passing a generic. I think if I improve the typing to where the key extends string it should be fine. Will look into it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set the correct typescript type for setValue in react- ...
I want to pass the function setValue() ...
Read more >
Argument of type not assignable to parameter type 'never'
This type represents an array that will never contain any elements (will always be empty). To solve the error, explicitly type the empty...
Read more >
Documentation - TypeScript 2.0
TypeScript has two special types, Null and Undefined, that have the values ... Because never is a subtype of every type, it is...
Read more >
TypeScript Data Type - Never
TypeScript introduced a new type never , which indicates the values that will never occur. The never type is used when you are...
Read more >
What is not assignable to parameter of type never error in ...
[ts] Argument of type 'string' is not assignable to parameter of type 'never'. What exactly am I doing wrong? typescript · error. May...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found