Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add static property to builtin type declaration

Tags:

typescript

TypeScript's built-in typings are currently missing AbortSignal.timeout. How does one write a .d.ts file to add it?

This doesn't work:

declare namespace AbortSignal {
  function timeout(milliseconds: number): AbortSignal;
}
Duplicate identifier 'AbortSignal'.(2300)
lib.dom.d.ts(1984, 11): 'AbortSignal' was also declared here.
lib.dom.d.ts(1996, 13): and here.
like image 877
Taymon Avatar asked Oct 22 '25 20:10

Taymon


1 Answers

If you are using TypeScript 4.5+, you can solve this by installing @types/web as a lib replacement:

pnpm add @typescript/lib-dom@npm:@types/web --save-dev
npm install @typescript/lib-dom@npm:@types/web --save-dev
yarn add @typescript/lib-dom@npm:@types/web --dev

This requires you to have "dom" in the lib-section of your tsconfig.json.

like image 152
leonheess Avatar answered Oct 24 '25 14:10

leonheess