Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move TextEncoder out of lib.dom.d.ts.

See original GitHub issue

Search Terms



Put (window|global).TextEncoder in a library that is automatically available to both browser and nodejs.

Use Cases

TextEncoder now exists on window in all major browsers as well as on global in NodeJS (as of NodeJS 11). At the moment, the TextEncoder definition lives in lib.dom.d.ts which means it isn’t available when working on a project/library that is targeting both NodeJS and Browser.

I don’t mind submitting a PR, but I don’t know where the appropriate location for such a change is, and how to reconcile it properly with removal from lib.dom.d.ts. It isn’t part of an annual ES specification, but it should go somewhere that is automatically included in both browser and node now that it is implemented by both. The specification for it can be found at and I believe that is what has been implemented in NodeJS.


My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

sandersncommented, Jul 10, 2019

Yes, for console, TextEncoder, and URL (and their associated types). Making users include dom typings is inaccurate if they only want those types.

MicahZoltucommented, Jul 10, 2019

While TextEncoder was moved in NodeJS 11 to match the web versions API, console has matched for a long time (not just NodeJS 11+). In a perfect world, all versions of node types would get console global from some shared location, while only node 11+ types would get TextEncoder from a shared location. I recognize this may complicate things even more though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TextEncoder | typescript - v3.7.7 - Microsoft Open Source
Defined in node_modules/typedoc/node_modules/typescript/lib/lib.dom.d.ts:15695. Returns the result of running UTF-8's encoder.
Read more >
TS 4.1 dropped the Position interface from lib.dom.d.ts. How ...
I have some TypeScript code that uses the Position interface from lib.dom.d.ts . I'm working to migrate to TS 4.1, in which the...
Read more >
node_modules/typescript/lib/lib.webworker.d.ts - Google Git
interface DOMMatrixInit extends DOMMatrix2DInit { ... d?: string;. dp?: string; ... Throws an "IndexSizeError" DOMException if the offset is out of range.
Read more >
Configuring Jest
The file will be discovered automatically, if it is named jest.config.js|ts|mjs|cjs|json . You can use --config flag to pass an explicit path to...
Read more >
twcam/gestion ... - IEEEsbUV
lib.dom.d.ts 678 KB ... Fires on the target object when the user moves the mouse out of a valid drop target during a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found