Prasad
Prasad

Reputation: 145

TS7006: Parameter 'event' implicitly has an 'any' type

In angular,

This is script

<button (click)="onClick($event)"> Greet </button>
     <button (click)="greeting='welcome' "> Greet </button> 
     {{greeting}}

This is event Logic

public greeting =""; 
 onClick(event) {
    console.log(event);
   this.greeting ='welcome';
  }

Upvotes: 14

Views: 37613

Answers (4)

hatem ghorbel
hatem ghorbel

Reputation: 135

in tsconfig.js change

"noImplicitAny": false to true or add it if it not found

Upvotes: 5

Sourav Das
Sourav Das

Reputation: 727

Reason: If you have any chance to use Angular in previous versions when you create a new project you might see some question like this. And this question is very important. enter image description here

Fix: You can either follow the stricter type checking rule or manually switch the stricter type checking to false. It worked for me. enter image description here

Upvotes: 7

Tejeshree
Tejeshree

Reputation: 962

On click of that button on console, we can see PoinerEvent { isTrusted": true }

So in addition to MouseEvent or Event you can also use:

onClick(event: PointerEvent) {}

Check the docs at PointerEvent MDN. "This interface inherits properties from MouseEvent and Event."

Upvotes: 1

richlira
richlira

Reputation: 519

Some alternatives you can use:

onClick(event: Event) {}

onClick(event: MouseEvent) {}

Also, if you are not using the parameter event for anything, you can remove it.

onClick() { ... }

Upvotes: 22

Related Questions