Skip to content
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

ts: Argument of type 'ReadonlyURLSearchParams' is not assignable to parameter of type 'string | #9578

Open
volfcan opened this issue Oct 15, 2024 · 1 comment

Comments

@volfcan
Copy link

volfcan commented Oct 15, 2024

Bug report

Describe the bug

I get this error on src/modules/checkout/components/payment/index.tsx file at createQueryString const.

ts: Argument of type 'ReadonlyURLSearchParams' is not assignable to parameter of type 'string | URLSearchParams | string[][] | Record<string, string> | undefined'.
Type 'ReadonlyURLSearchParams' is not assignable to type 'URLSearchParams'.
The types returned by 'Symbol.iterator' are incompatible between these types.
Type 'IterableIterator<[string, string]>' is missing the following properties from type 'URLSearchParamsIterator<[string, string]>': map, filter, take, drop, and 9 more.

System information

Medusa version (including plugins):
Node.js version:
Database:
Operating system:
Browser (if relevant):

Steps to reproduce the behavior

  1. Go to 'https://github.com/volfcan/medusa-frontend'
  2. Clone the repository
  3. See error

Expected behavior

No errors

Screenshots

Screenshot 2024-10-15 at 10 17 31

Code snippets

  const createQueryString = useCallback(
    (name: string, value: string) => {
      const params = new URLSearchParams(searchParams)
      params.set(name, value)

      return params.toString()
    },
    [searchParams]
  )
@Sankalpcreat
Copy link

const params = new URLSearchParams(Array.from(searchParams.entries())); should be added in that
Screenshot 2024-10-16 at 3 01 11 PM

  1. compatibility with URLSearchParams
  2. It converts the ReadonlyURLSearchParams into a format that can be directly used to create a new instance of URLSearchParams

This approach is perfectly valid and should fix the type error while allowing you to modify the query string as needed.

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

No branches or pull requests

2 participants