Definitelytyped: [got] error TS2304: Cannot find name 'URL'

Created on 16 Sep 2017  路  6Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [X] I tried using the @types/xxxx package and had problems.
  • [X] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [X] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @BendingBender @LinusU

I get this error when trying to use typings for the got package:

node_modules/@types/got/index.d.ts(85,50): error TS2304: Cannot find name 'URL'.

Not sure if that's the cause, but this definition imports Url (that is not used) and uses URL (that is not imported).

node v6.11.2
npm 3.10.10
typescript 2.5.2

Most helpful comment

I don't understand the rationale for closing this one. Is it acceptable to include the dom even if it isn't actually available?

All 6 comments

URL is available in the dom typings provided by TypeScript. It's a global there so it doesn't need to be explicitly imported. It's the same type that is exported by the url module in node typings in v7 and 8. This way I've tried to make this module usable for users of node typings <7.

And Url is actually used here.

Thanks @BendingBender. I solved this by adding dom to the libs in tsconfig.json.

I was actually thinking of brining this up earlier but never got the time. In my backend projects I don't feel that I should need to enable dom since that's not available in that environment...

I'm not sure if there is any better solutions though, but one way could be to type a small interface of the props that got actually looks at. It's to my understanding that it would then be perfectly fine to pass it an URL class

Same for me here (like @LinusU said). got is a universal package and so is my package. It might be running in a DOM environment, but might also be running in node.

Thus adding @types/dom would be quite a dirty hack, since we cannot rely on any DOM stuff to be available.

I don't understand the rationale for closing this one. Is it acceptable to include the dom even if it isn't actually available?

I don't like this solution either, but it works. I think it would be better if got do not depend on @types/dom.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamespero picture jamespero  路  3Comments

jbreckmckye picture jbreckmckye  路  3Comments

JWT
svipas picture svipas  路  3Comments

Loghorn picture Loghorn  路  3Comments

victor-guoyu picture victor-guoyu  路  3Comments