question-mark
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.

TypeScript interface for abort signal not compatible with AbortController

See original GitHub issue

I have installed node-fetch 2.6.0, using inside Electron 8 with Chromium 80.0 I think:

	const controller = new AbortController()
	const signal:AbortSignal = controller.signal;
	const timeout = setTimeout(() => { 
		controller.abort(); 
	}, 15000);

	const res = await fetch(`https://api.keygen.sh/v1/accounts/${KEYGEN_ACCOUNT_ID}/licenses/actions/validate-key`, {
		method: 'POST',
		signal: signal,
		headers: {
			'Content-Type': 'application/vnd.api+json',
			'Accept': 'application/vnd.api+json'
		},
		body: JSON.stringify({
			meta: {
				scope: { product: KEYGEN_PRODUCT_ID },
				key: license_key
			}
		}),
	})

I get the following error:

electron/main/main.ts:268:114 - error TS2345: Argument of type '{ method: string; signal: AbortSignal; headers: { 'Content-Type': string; 'Accept': string; }; body: string; }' is not assignable to parameter of type 'RequestInit'.
  Types of property 'signal' are incompatible.
    Type 'AbortSignal' is not assignable to type 'import("/Users/sakari/dvl/omg/client-standalone/electron/node_modules/@types/node-fetch/externals").AbortSignal'.
      Types of property 'onabort' are incompatible.
        Type '((this: AbortSignal, ev: ProgressEvent) => any) | null' is not assignable to type '((this: AbortSignal, event: any) => void) | null | undefined'.
          Type '(this: AbortSignal, ev: ProgressEvent) => any' is not assignable to type '(this: AbortSignal, event: any) => void'.
            The 'this' types of each signature are incompatible.
              Type 'import("/Users/sakari/dvl/omg/client-standalone/electron/node_modules/@types/node-fetch/externals").AbortSignal' is not assignable to type 'AbortSignal'.
                Types of property 'onabort' are incompatible.
                  Type '((this: AbortSignal, event: any) => void) | null | undefined' is not assignable to type '((this: AbortSignal, ev: ProgressEvent) => any) | null'.
                    Type 'undefined' is not assignable to type '((this: AbortSignal, ev: ProgressEvent) => any) | null'.

268  const res = await fetch(`https://api.keygen.sh/v1/accounts/${KEYGEN_ACCOUNT_ID}/licenses/actions/validate-key`, {

Just installed latest version of abort-controller and tsc Version 3.3.3333. How to fix this ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Sakari369commented, Feb 28, 2020

Yup, commenting out the import of AbortSignal from ‘node_modules/@types/node-fetch/index.d.ts’ fixes this:

// Type definitions for node-fetch 2.5
// Project: https://github.com/bitinn/node-fetch
// Definitions by: Torsten Werner <https://github.com/torstenwerner>
//                 Niklas Lindgren <https://github.com/nikcorg>
//                 Vinay Bedre <https://github.com/vinaybedre>
//                 Antonio Román <https://github.com/kyranet>
//                 Andrew Leedham <https://github.com/AndrewLeedham>
//                 Jason Li <https://github.com/JasonLi914>
//                 Brandon Wilson <https://github.com/wilsonianb>
//                 Steve Faulkner <https://github.com/southpolesteve>
//                 ExE Boss <https://github.com/ExE-Boss>
//                 Alex Savin <https://github.com/alexandrusavin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import { Agent } from "http";
import { URLSearchParams, URL } from "url";
//import { AbortSignal } from "./externals";

Fixes the collision. Maybe you should somehow detect this or something ?

0reactions
googolcommented, Apr 9, 2020

Oh yeah, I don’t know how I read the compiler error earlier, it was about onabort all along, not dispatchEvent 🤦‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

AbortSignal | typescript - v3.7.7
A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an...
Read more >
AbortSignal - Web APIs - MDN Web Docs - Mozilla
The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort...
Read more >
AbortController missing in TypeScript - fetch api - Stack Overflow
I am trying to use AbortController in TypeScript. TypeScript has documentation about AbortController. I also found an issue from Github which ...
Read more >
The complete guide to AbortController in Node.js
It is a handy API for aborting some asynchronous processes, similar to the AbortController interface in the browser environment.
Read more >
Aborting fetch request with AbortController - miyauci.me
The AbortController has a reference to the signal object and an abort method. You can abort an HTTP request by passing this signal...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found