CrazySynthax CrazySynthax - 3 years ago 75
TypeScript Question

Browser API: URL class is not recognized in Typescript

I'm using URL utility: and I have a problem using it in Typescript code.

Whereas I can open the console in the browser and type:

new URL("")

and the code is successful, whenever I write it in Typescript file and transpile it, I get the following error:

error TS2351: Cannot use 'new' with an expression whose type lacks a
call or construct signature.

Does it mean that this class doesn't exist in Typescript? Is there any way to use it in Typescript code?

Answer Source

That should be supported by TypeScript, actually that's included on lib.dom.d.ts which is included by default if your target is es5.

You can also configure it on tsconfig.json (that is the default config when using es5, but you can try to add it explicitly):

"lib": [
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download