Не могу использовать GamepadEvent при использовании addEventListener - PullRequest
0 голосов
/ 21 апреля 2020

У меня есть следующий код в машинописи:

window.addEventListener ('gamepadconnected', (e: GamepadEvent) => {console.log (e.gamepad)});

Но я получил следующие ошибки:

No overload matches this call.
  Overload 1 of 2, '(type: "abort" | "afterprint" | "beforeprint" | "beforeunload" | "blur" | "canplay" | "canplaythrough" | "change" | "click" | "compassneedscalibration" | "contextmenu" | "dblclick" | ... 122 more ... | "unhandledrejection", listener: (this: Window, ev: Event | ... 22 more ... | PromiseRejectionEvent) => any, options?: boolean | ... 1 more ... | undefined): void', gave the following error.
    Argument of type '"gamepadconnected"' is not assignable to parameter of type '"abort" | "afterprint" | "beforeprint" | "beforeunload" | "blur" | "canplay" | "canplaythrough" | "change" | "click" | "compassneedscalibration" | "contextmenu" | "dblclick" | ... 122 more ... | "unhandledrejection"'.
  Overload 2 of 2, '(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void', gave the following error.
    Argument of type '(e: GamepadEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
      Type '(e: GamepadEvent) => void' is not assignable to type 'EventListener'.
        Types of parameters 'e' and 'evt' are incompatible.
          Property 'gamepad' is missing in type 'Event' but required in type 'GamepadEvent'.ts(2769)

но это должно быть возможно => https://developer.mozilla.org/en-US/docs/Web/API/Window/gamepadconnected_event

Почему, я должен потерять тип и поставить любой ?

...