use-query-params icon indicating copy to clipboard operation
use-query-params copied to clipboard

encodeQueryParam: wrong agument type for query

Open prayogoa opened this issue 9 months ago • 1 comments

consider a query param config with asymmetric encoded and decoded type:

const NumberToStringParam: QueryParamConfig<number, string> = {
  encode: (value) => value.toString(),
  decode: (value) => {
    if (typeof value !== 'string') {
      return ''
    }
    return value ?? ''
  }
}

This will fail the typecheck:

encodeQueryParams({
  foo: NumberToStringParam
},
{
  foo: 123
})

TS Playground link

prayogoa avatar Apr 02 '25 10:04 prayogoa

Looks like there's already a PR to fix this https://github.com/pbeshai/use-query-params/pull/272

prayogoa avatar Apr 02 '25 10:04 prayogoa