abort-controller icon indicating copy to clipboard operation
abort-controller copied to clipboard

TypeScript support is broken

Open nazar-pc opened this issue 6 years ago • 1 comments

Looks like after rewrite to TypeScript "types" key in package.json was lost, which is necessary for be useful in TypeScript.

nazar-pc avatar Jul 03 '19 12:07 nazar-pc

I don't know if this is related, but with this code

	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.

Sakari369 avatar Feb 28 '20 11:02 Sakari369