3

I have in my Sample.html somewhere defined

<input  (keydown.Enter)="onKeyEnter($event)" ...

In my Sample.ts I have defined

  onKeyEnter(event: KeyboardEvent): void {
    ....
    event.preventDefault();
    event.stopPropagation();
  }

I get with strictTemplates the failure

error TS2345: Argument of type 'Event' is not assignable to parameter of type 'KeyboardEvent'.

Which is somehow strange because in the input one can get only the a KeyboardEvent. Is there a way to get rid of this error? Which I see as false positive.

LeO
  • 4,238
  • 4
  • 48
  • 88

1 Answers1

1

it's not the same event keydownthan keydown.enter, as the own Angular say

Type 'Event' is missing the following properties from type 'KeyboardEvent': altKey, char, charCode, code, and 16 more.

You can use "any"

onKeyEnter(event: any): void {
}

Update or Event

onKeyEnter(event: Event): void {
}
Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • But if you wanna have the `strict` options on than `any` wouldn't be allowed. BTW: you have link to your quote? – LeO Oct 20 '20 at 19:00
  • Just create a stackblitz:https://stackblitz.com/edit/angular-ivy-drsyrq?file=src%2Fapp%2Fapp.component.ts. NOTE, You can use also `Event` as type of the variable. (I updated the answer). I'm trying look the github fonts about keydown in Angular. If I'll find, I'll update the answer again. – Eliseo Oct 20 '20 at 19:08