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.

io-ts typing invalid

See original GitHub issue

Describe the bug Example, copied from README.MD does not work, triggering error on “resolver” property. I had to replace ref on username with {...register('username')} because the typing failed there too, but looks unrelated to resolver (I guess example with ref is outdated for this react-hook-form example).

To Reproduce See sandbox

Codesandbox link (Required) https://codesandbox.io/s/priceless-gareth-hs0zo?file=/src/App.tsx

Expected behavior No type error

Desktop (please complete the following information):

  • OS: linux
  • Browser firefox
  • Version 89

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jorisrecommented, Jun 14, 2021

Hi @akomm,

You’ve to pass yourself the type definition of your form data:

import * as t from "io-ts";
import { useCallback } from "react";
import { useForm } from "react-hook-form";
import { ioTsResolver } from "@hookform/resolvers/io-ts";

const schema = t.type({
  file: t.string
});

interface FormData {
  file: string;
}

export default function App() {
  const { register, handleSubmit } = useForm<FormData>({
    resolver: ioTsResolver(schema)
  });

  const onSubmit = useCallback((values: unknown) => {
    console.log(values);
  }, []);

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input type="file" {...register("file")} />
      <button type="submit">submit</button>
    </form>
  );
}

I’m not a user of io-ts, but I think you can do something as Zod do: https://github.com/colinhacks/zod#type-inference

Here is how to use TypeScript with useForm: https://react-hook-form.com/ts#UseFormProps

Hope it helps 😃

1reaction
github-actions[bot]commented, Jun 19, 2021

🎉 This issue has been resolved in version 2.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

SyntaxError: invalid from typing import TYPE_CHECKING · ...
Virtual env was created and I edited the pipfile.lock once before creating the env Is this a bug or problem with my environment?...
Read more >
[SOLVED] Keyboard Typing Wrong Letters (2022)
Your keyboard keeps typing wrong letters? You're not alone! Many Windows users are reporting it. But the good new is you can fix...
Read more >
How to Fix Keyboard Typing Wrong Character or Keys Not ...
If still problem not fixed contact me on fb...https://www.facebook.com/mjtube11Keyboard codes...
Read more >
Keyboard typing weird letters and symbols
Keyboard typing weird letters and symbols. Hi all. I have tried to use my Macbook Pro this morning and when I type its...
Read more >
Keyboard typing wrong characters on windows 10
Try connecting the keyboard to a different USB port if its a USB wired keyboard. Press Windows key + X Click Device Manager...
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