react-native-url-polyfill
react-native-url-polyfill copied to clipboard
Typescript error: Expected 0 arguments, but got 1.ts(2554) (parameter) url: string
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?
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
.
Same error with me
:
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';
).
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.
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.
Im having the same issue
Using the JS entry point import (Option 1) in place of the per file import (Option 3) resolved the issue on my end.
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 Yes I have submitted a PR.
I'll close this issue as it was resolved by #444, thank you, @raykle!
It will soon be published on npm.