Skip to content

TypeScript error: "Type 'AbortSignal' is missing the following properties from type 'AbortSignal': reason, throwIfAborted" #36

@OliverJAsh

Description

@OliverJAsh

Using latest version of all packages at time of writing:

package.json:

{
  "dependencies": {
    "@types/node": "^17.0.42",
    "abort-controller": "^3.0.0",
    "typescript": "^4.7.3"
  }
}

main.ts:

import AbortController from "abort-controller";

/*
Type 'typeof AbortController' is not assignable to type '{ new (): AbortController; prototype: AbortController; }'.
  The types of 'prototype.signal' are incompatible between these types.
    Type 'AbortSignal' is missing the following properties from type 'AbortSignal': reason, throwIfAborted
*/
globalThis.AbortController = AbortController;

We can fix it by using the global AbortController type:

diff --git a/node_modules/abort-controller/dist/abort-controller.d.ts b/node_modules/abort-controller/dist/abort-controller.d.ts
index 75852fb..aa25471 100644
--- a/node_modules/abort-controller/dist/abort-controller.d.ts
+++ b/node_modules/abort-controller/dist/abort-controller.d.ts
@@ -24,20 +24,6 @@ declare class AbortSignal extends EventTarget<Events, EventAttributes> {
  * The AbortController.
  * @see https://dom.spec.whatwg.org/#abortcontroller
  */
-declare class AbortController {
-    /**
-     * Initialize this controller.
-     */
-    constructor()
-    /**
-     * Returns the `AbortSignal` object associated with this object.
-     */
-    readonly signal: AbortSignal
-    /**
-     * Abort and signal to any observers that the associated activity is to be aborted.
-     */
-    abort(): void
-}
-
+declare const AbortController: typeof globalThis.AbortController;
 export default AbortController
 export { AbortController, AbortSignal }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions