pbeshai / use-query-params

React Hook for managing state in URL query parameters with easy serialization.
https://pbeshai.github.io/use-query-params
ISC License
2.13k stars 95 forks source link

Typescript warning in serialize-query-params for createEnumArrayParam (when following readme ) #269

Open arnthors opened 1 year ago

arnthors commented 1 year ago

The readme gives the following code example: const ColorArrayEnumParam = createEnumArrayParam<Color[]>(['red', 'green', 'blue']) but this raises the following typescript warning Type 'Color[]' does not satisfy the constraint 'string'.ts(2344)

This makes sense when looking at the Typescript declarations for createEnumArrayParam which is as follows: declare const createEnumArrayParam: <T extends string>(enumValues: T[])

This illustrates that only T is expected as a generic type parameter declaration while the expected function parameter is an array of T.

So I believe the solution here is update the Readme from: const ColorArrayEnumParam = createEnumArrayParam<Color[]>(['red', 'green', 'blue']) to: const ColorArrayEnumParam = createEnumArrayParam<Color>(['red', 'green', 'blue'])