react-native-url-polyfill icon indicating copy to clipboard operation
react-native-url-polyfill copied to clipboard

Typescript error: Expected 0 arguments, but got 1.ts(2554) (parameter) url: string

Open kmvan opened this issue 2 years ago • 7 comments

import { URL } from 'react-native-url-polyfill'

const urlObj = new URL(url) // Expected 0 arguments, but got 1.ts(2554) (parameter) url: string

Any idea?

kmvan avatar Oct 22 '21 04:10 kmvan

What's the type for NativeURL do you have?

https://github.com/charpeni/react-native-url-polyfill/blob/29942dda661fceb1a0307249bcacca177f5b79b9/index.d.ts#L2

Mine is from @types/node/url.d.ts.

charpeni avatar Oct 29 '21 21:10 charpeni

Same error with me Captura de Tela 2021-11-11 às 20 50 09 :

AroldoGoulart avatar Nov 12 '21 00:11 AroldoGoulart

I've been using this pollyfill for quite some time in my project. I upgraded a few RN packages (not RN itself or anything to do with typings or this behavior) and all the sudden I started getting the same error (and many more related to the polyfill seeming to not exist anymore in my project).

Note, I'm using the direct import method (e.g. import { URL } from 'react-native-url-polyfill';).

jspizziri avatar Jun 17 '22 13:06 jspizziri

I reverted my dependency upgrades and I can confirm that the polyfill was working again. So I examined all reapplied all my dependency changes one by one and identified the one that was causing the issue:

react-native-gesture-handler@^1.9.0 -> ^2.4.2

It seems upgrading to the latest version here is somehow breaking the polyfill. Interestingly I do see some references in the platforms folder to the react-native-gesture-handler package.

@charpeni any insights on what could be going wrong here? I'd be happy to submit a PR to fix it if I understood the issue.

jspizziri avatar Jun 17 '22 13:06 jspizziri

Hi @jspizziri, I'm facing the issue, and I finally resolve the issue by adding the code below at the first line of index.d.ts through patch-package. I tried this by referring to other packages.

+/// <reference types="node" />
 declare module 'react-native-url-polyfill' {

Happy to know the reason if somebody knows.

raykle avatar Sep 09 '22 01:09 raykle

Im having the same issue

17Amir17 avatar Sep 13 '22 22:09 17Amir17

Using the JS entry point import (Option 1) in place of the per file import (Option 3) resolved the issue on my end.

ad-walker avatar Sep 21 '22 15:09 ad-walker

Hi, I face the this issue when working with this lib. Additionally, such issue does not allow to retrieve the fields from the URL object. The solution from @raykle seems to fix the issue. @raykle can you make a PR with your fix so it gets merged?

PS: The solution from @ad-walker works with JS, but not with TS where I still face the issue.

pasquale95 avatar Dec 19 '22 08:12 pasquale95

@pasquale95 Yes I have submitted a PR.

raykle avatar Dec 19 '22 12:12 raykle

I'll close this issue as it was resolved by #444, thank you, @raykle!

It will soon be published on npm.

charpeni avatar Jul 07 '23 14:07 charpeni