I have a Node.js project that is built with TypeScript I'm trying to use URLSearchParams, however I can see the following error:
Cannot find name 'URLSearchParams'.ts(2304)
const params = new URLSearchParams();
params.append("foo", 5);
typescript: ^3.9.7
node.js: v12.16.3
                Node is an open source project that is used to create dynamic web applications. The URLSearchParams API is an interface. It defines different utility that is required to work with the query string of the URL.
While URLSearchParams has lived on the global object in node since v10.0.0, it can be hard to pull ambient type information from there.
The URLSearchParams class lives in the url module, so you can also import it directly from there:
import { URLSearchParams } from "url"
then use it like this:
let queryString = new URLSearchParams({page: "1", pagesize: "100"}).toString();
Also, make sure you install types for node
npm install @types/node --save-dev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With