TypeScript 5.5+ declaration of AbortSignal conflicts with Node.js v14 types
๐ Search Terms
Steps to reproduce:
mkdir typescript-5-node-14
cd typescript-5-node-14
npm i typescript @types/node@14
touch index.ts
npx tsc index.ts
As of writing, this installs TypeScript 5.8.2 and @types/node 14.18.63.
๐ Version & Regression Information
- This changed between versions 5.4 and 5.5
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
๐ Actual behavior
node_modules/@types/node/globals.d.ts:126:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'AbortSignal' must be of type '{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; any(signals: AbortSignal[]): AbortSignal; timeout(milliseconds: number): AbortSignal; }', but here has type '{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; timeout(milliseconds: number): AbortSignal; }'.
126 declare var AbortSignal: {
~~~~~~~~~~~
node_modules/typescript/lib/lib.dom.d.ts:2606:13
2606 declare var AbortSignal: {
~~~~~~~~~~~
'AbortSignal' was also declared here.
Found 1 error in node_modules/@types/node/globals.d.ts:126
๐ Expected behavior
Compilation without errors.
Additional information about the issue
It works fine if TypeScript <= 5.4 is used.
lib.dom.d.ts describes the types of a fully compliant web browser (the HTML platform). @types/node describes the types of a full Node.js environment. I wouldn't expect the two to be compatible, and there is no real js environment that perfectly 100% implements both of these at the same time.
This feels like a duplicate of or closely related to https://github.com/microsoft/TypeScript/issues/43972.
Ok, but why is TypeScript including lib.dom.d.ts by default? It's not needed for projects that solely target node.js. Is there a way to turn it off?
Legacy reasons. Browser used to be the default target for people's code.
https://www.typescriptlang.org/tsconfig/#lib
You may want to change these for a few reasons:
Your program doesnโt run in a browser, so you donโt want the"dom"type definitions
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.