TypeScript: KeyboardEventInit missing props

The KeyboardEvent list is props is here:

TypeScript Version:
2.1.6 Code I’m trying to create a KeyboardEvent

    let e = new KeyboardEvent("keyup", {
      bubbles : true,
      cancelable : true,
      charCode : "1",
      key : "1",
      shiftKey : true,
      keyCode : 81
    });

Expected behavior: No error Actual behavior: I get error:

ERROR in /Users/nikos/WebstormProjects/angular-finance/tests/src/app/app.component.spec.ts (33,7): Argument of type '{ bubbles: true; cancelable: true; char: string; key: string; shiftKey: true; keyCode: number; }' is not assignable to parameter of type 'KeyboardEventInit'.
  Object literal may only specify known properties, and 'char' does not exist in type 'KeyboardEventInit'.)

Because this only has 4 props:

image

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Any updates on this? Or any workaround for creating proper keyboard events?

in overridingTypes.json, add:

    {
        "kind": "constructor",
        "interface": "KeyboardEvent",
        "signatures": ["new(type: string, eventInitDict?: KeyboardEventInit): KeyboardEvent"]
    },