TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

TypeScript 5.5+ declaration of AbortSignal conflicts with Node.js v14 types

Open siddharthvp opened this issue 10 months ago โ€ข 3 comments

๐Ÿ”Ž 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.

siddharthvp avatar Mar 19 '25 14:03 siddharthvp

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.

nmain avatar Mar 19 '25 14:03 nmain

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?

siddharthvp avatar Mar 19 '25 15:03 siddharthvp

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

MartinJohns avatar Mar 19 '25 15:03 MartinJohns

This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

typescript-bot avatar Mar 23 '25 01:03 typescript-bot