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.

typing warning with Chakra UI's `Input` on sample-app

See original GitHub issue

Running the sample-app example on this repository, which uses Chakra UI, seems to be giving a Type 'string' is not assignable to type 'never'. ts(2322) warning on the id property at app/components/FormInput.jsx:30. Including the snippet here for easier reading:

// ...

  return (
    <>
      <FormControl isInvalid={!!error} isRequired={isRequired}>
        <FormLabel htmlFor={name}>{label}</FormLabel>
        <Input
          {...getInputProps({
            id: name,
            ...rest,
          })}
        />
        {error && <FormErrorMessage>{error}</FormErrorMessage>}
      </FormControl>
    </>
  );

Now, everything still seems to work fine and my experience with Chakra UI is none so I might be missing something obvious, but seeing as this is an official example I’m wondering if there’s anything to be done about it…

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
airjp73commented, Jan 24, 2022

@rmobis, I’m going to end up reverting that fix, I think. I’m working on adding to getInputProps and running into issues with the current typing. I’ve tried the old typing with other component libraries and Chakra seems to be the only one with this issue.

For an alternate fix, you can get the correct functionality without as never or as any is by supplying the generic directly.

import { Input, InputProps } from '@chakra-ui/react';

<Input {...getInputProps<InputProps>({ id: name, ...rest })} />
1reaction
airjp73commented, Jan 21, 2022

I found a solution and will publish it. Somehow switching from Omit<T, 'defaultValue' | 'name'> to T & { defaultValue?: never, name?: never } fixed it. One downside to this is that defaultValue and name show up as autocomplete options, but it still prevents you from setting them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Input - Chakra UI
Input component is a component that is used to get user input in a text field.
Read more >
Get Chakra UI working with Remix Run · Issue #5166 - GitHub
I've tried adding the provider to the server.entry file and using the provided solution @primos63 added above. Neither seems to fix the issue....
Read more >
How to create forms with Chakra UI in React apps
I've been using this UI library for a recent project and thought exploring it more might be a good idea. Learn how to...
Read more >
How to build a Habit Tracker with Prisma, Chakra UI, and React
In this tutorial, you'll learn how to built a Habit Tracker app “Streaks” from scratch with Prisma, Chakra UI, and React. We use...
Read more >
Chakra UI and React-Hook-Form –How to Build Beautiful Forms
Chakra UI and React-Hook-Form –How to Build Beautiful Forms ... <form onSubmit={handleSubmit(onSubmit)}> <input type=”text” ...
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