Skip to content

encodeQueryParam: wrong agument type for query #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
prayogoa opened this issue Apr 2, 2025 · 1 comment
Open

encodeQueryParam: wrong agument type for query #297

prayogoa opened this issue Apr 2, 2025 · 1 comment

Comments

@prayogoa
Copy link

prayogoa commented Apr 2, 2025

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
Copy link
Author

prayogoa commented Apr 2, 2025

Looks like there's already a PR to fix this #272

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant