Closed5

@types/node と lib.dom.d.ts

tasshitasshi

Node.js 向けのコードベースで tscofig.jsonlib"dom" を指定しないとURL, fetch, Stream APIなどのWHATWG準拠のAPIが使えない。

結論

結論としては @types/node のバージョンを上げたら解決した。

tasshitasshi

関連するIssue

@types/node (Apr 24, 2019)

URLURLSearchParams のグローバルな型を入れようという提案。

過去に入れた結果、lib.dom.d.ts と競合してエラーが発生したため削除したという経緯があるらしい。

Because lib.dom.d.ts also exposes them as globals, projects which referenced both, node and lib.dom, got "Duplicate identifier 'URL'" errors (see #25342). Therefore the global URL and URLSearchParams has been removed again.

This fix (actually a workaround for a missing declaration merging feature of TypeScript) now has the drawback that we cannot use the global URL class in Node.js-code (instead we need to import it from the url module). This is especially bad for universal modules which are supposed to work in the browser + node by just using the global URL (which works since Node.js 10).

https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960

TypeScript (Nov 30, 2020)

lib.dom.d.tsをもっと細かく機能ごとに指定できるようにして欲しいという提案

回答としてはDOMの型をメンテするのは好まず、またコミュニティが @types/node を管理しているのでモチベーションとしては低い

There's a growing Venn diagram here with Webworkers; the truth is that we don't even like maintaining the DOM types and sent Node to community management, so our appetite for tackling this is quite low. Maybe someone can automate a process that produces good lib files based on intersection -- if that required a few tweaks on our side to make work right, we'd be interested to help out.

https://github.com/microsoft/TypeScript/issues/41727

その他

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

https://github.com/DefinitelyTyped/DefinitelyTyped/issues/19799#issuecomment-330188352

Furthermore, I am a bit unsure of adding any kind of DOM dependencies to a application, which will run purely in Node, as most of the DOM stuff (apart from e.g. this URL :) ) is not available when running in Node. Perhaps I could try to make a PR to this repo to fix this issue? Or is this library intended to be used only in browser, starting from version 2?

https://github.com/microsoft/ApplicationInsights-node.js/issues/794#issuecomment-889673234

このスクラップは5ヶ月前にクローズされました