TypeScript interface for abort signal not compatible with AbortController
See original GitHub issueI 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:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yup, commenting out the import of AbortSignal from ‘node_modules/@types/node-fetch/index.d.ts’ fixes this:
Fixes the collision. Maybe you should somehow detect this or something ?
Oh yeah, I don’t know how I read the compiler error earlier, it was about
onabort
all along, notdispatchEvent
🤦♂️