Generic type 'ControlProps' requires 2 type argument(s). TS2314
See original GitHub issueAre you reporting a bug or runtime error?
Yes, but in TypeScript.
Description
I can’t figure out what in the react-select changelog caused this but upgrading to react-select@3.1.1 has broken my Chromatic deployments so I’m assuming the type of something changed.
Here’s the error:
Generic type 'ControlProps' requires 2 type argument(s). TS2314
And the code that caused it:
export const controlStyles = (base: CSSProperties, state: ControlProps<{}>) => ({
...base,
height: "3.2rem"
})
This error is actually originating from a lot of types I’ve used from @types/react-select
including NoticeProps, OptionProps, ValueType, etc. I’m assuming it’s because of the upgrade because with react-select@3.1.0, everything worked smoothly.
Feel free to look at the logs of the errors for more details or the source.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15
Top Results From Across the Web
How to use typescript with the definition of custom styles for a ...
StyleConfig requires you to pass at least 2 generic type variables according to this declaration here. OptionType : The option type of react- ......
Read more >generic type 'ɵɵcomponentdeclaration' requires 7 type ...
Here's the error: Generic type 'ControlProps' requires 2 type argument(s). TS2314. And the code that caused it: tsx export const controlStyles = (base: ......
Read more >error ts2314: generic type 'component<p, s>' requires 2 type ...
In this instance, identities takes 2 arguments and returns them in an array. It's a detail unrelated to generics, but if you use...
Read more >TypeScript react-select cheat sheet - SaltyCrane
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. This is a list of TypeScript types for react-select generated from...
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
Running into the same issue as well but with ValueType, been using this package for over a year on a client’s project and it broke all of our pipelines. In the future you guys should make type changes like that a major version upgrade not a minor so it doesn’t break builds.
@cseas
The
IsMulti
generic makes it so that we can correctly narrowValueType
in various scenarios. PreviouslyValueType
looked like this:Now it looks like this:
What does this mean? It means that if we’re dealing with a single-select component (
IsMulti
isfalse
) then we know thatValueType
will not be an array. But if we know that we’re dealing with a multi-select component (IsMulti
istrue
) then we know thatValueType
will be an array.A practical example (see this CodeSandbox for the full code) where this makes a difference is the callback function passed into the
onChange
prop which provides an argument of typeValueType<OptionType>
as it’s first parameter. Previously code like this would result in a type error:However we know that it’s not an array because this isn’t a multi-select component and we shouldn’t have to cast. Therefore we can now set the second generic parameter to
false
to specify that this is not a multi-select component and now it compiles correctly:It is part of the
Props
type, it’s just that it defaults tofalse
(and is therefore optional). If you don’t provide it, and you don’t set theisMulti
prop totrue
, it will set it tofalse
and assume you’re dealing with a single-select component.