'AbortController polyfill

Tried to make a polyfill for the abortController, but I ran into this error: error image

Error: Failed to execute 'fetch' on 'Window': Failed to read the 'signal' property from 'RequestInit': Failed to convert value to 'AbortSignal'.
class AbortSignalPolyfill extends EventTarget {
  readonly aborted: boolean = false
  onabort() {}
  addEventListener() {}
  removeEventListener() {}
}

class AbortControllerPolyfill {
  readonly signal = new AbortSignalPolyfill()
  abort() {}
}

;(function () {
  if (
    typeof window.Request === 'function' &&
    Object.prototype.hasOwnProperty.call(window.Request, 'signal') &&
    window.AbortController
  ) {
    return
  }

  Object.defineProperty(window, 'AbortController', {
    writable: true,
    enumerable: false,
    configurable: true,
    value: AbortControllerPolyfill,
  })

  Object.defineProperty(window, 'AbortSignal', {
    writable: true,
    enumerable: false,
    configurable: true,
    value: AbortSignalPolyfill,
  })
})()

Can anyone tell me why? Maybe the problem is in the abortControllerPolyfill and abortSignalPolyfill.

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source