3

I'm using URL utility: https://developer.mozilla.org/en-US/docs/Web/API/URL and I have a problem using it in Typescript code.

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

new URL("http://stackoverflow.com/question/ask")

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?

1 Answer 1

5

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": [
            "dom",
            "es5",
            "scripthost"
        ],
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.