I am currently working with Vue and TypeScript, and I have a requirement to call the application using a specific URL format like:
http://localhost:5173?foo=bar
This needs to be done without requiring a route hash. Here is the code snippet that I am using:
const getUrlParameter = (name: string) => {
const url = new URL(window.location);
const parameter = url.searchParams.get(name);
// ...
};
When passing in 'foo'
, it successfully returns bar
which indicates that it functions as intended. However, TypeScript throws an error message:
TS2345: Argument of type 'Location' is not assignable to parameter of type 'string | URL'. Type 'Location' is missing the following properties from type 'URL': password, searchParams, username, toJSON
Should I ignore this error message or are there any solutions to resolve it?