V5: Custom selectProps require ts-ignore in Typescript
See original GitHub issueHi, congrats on the big v5 release!
After upgrading to v5, use of custom props on Select cause errors in Typescript. They still seem to work but require ts-ignore directive to silence the error.
Example:
<Select<MyOption>
id={id}
options={options}
{... more props ...}
components={{ SingleValue }}
myCustomProp='foobar'
/>
function SingleValue({ children, ...props }: SingleValueProps<MyOption>) {
return (
<div>
<label htmlFor={selectProps.name}>
{props.selectProps.myCustomProp}
</label>
<components.SingleValue {...props}>{children}</components.SingleValue>
<div className="ml-1">
<components.DownChevron />
</div>
</div>)
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:12 (2 by maintainers)
Top Results From Across the Web
How to use `@ts-ignore` for a block? - Stack Overflow
As a workaround you can use a // @ts-nocheck comment at the top of a file to disable type-checking for that file: ...
Read more >Styles - React Select
The recommended way to provide custom styles to react-select is to use the styles prop. styles takes an object with keys to represent...
Read more >react-select - npm
TypeScript. The v5 release represents a rewrite from JavaScript to TypeScript. The types for v4 and earlier releases are available at @types.
Read more >material-ui/core/CHANGELOG.md - UNPKG
219, - Simplify the theme overrides with TypeScript for the components in the lab (#21279) ... 1290, - [docs] Remove `@ts-ignore` usage (#19504)...
Read more >ban-ts-comment - TypeScript ESLint
Disallow `@ts- ` comments or require descriptions after directives. ... ts-expect-error , ts-ignore , ts-nocheck , ts-check directives.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry, I forgot to include how to type custom
selectProps
in the upgrade guide and TypeScript usage documentation. I’ll work on adding that documentation.The only reason this worked for
@types/react-select
is because there was an index signature that would type any unknown prop asany
. This was a little bit too loose and was causing numerous problems. In order to do this in v5 you’ll need to use module augmentation to augment the type of the Select props. Here’s how to update your example so it works in v5:Let me know if that works for you.
No, unfortunately there’s no way to specify it per component. Note there also wasn’t a way to do this for
@types/react-select
either. If you want to go back to that behavior you can just augment the props with an index signature that allows any prop.I’ve looked into trying to make it so that the custom props could be another generic on the
Select
component, but it made the types much more complex and I think I had trouble getting it working well. Feel free to give it a try yourself and we’d be happy to merge a PR if it doesn’t add too much complexity.