Anuj Todankar
Anuj Todankar

Reputation: 43

Argument of type 'any' is not assignable to parameter of type 'never'?

Parameter 'post' implicitly has an 'any' type. Argument of type 'any' is not assignable to parameter of type 'never'

storedPosts=[];
  OnPostAdded(post){
    this.storedPosts.push(post);
  }

Upvotes: 1

Views: 4612

Answers (4)

tebkanlo
tebkanlo

Reputation: 181

It might be redundant to say it, but in my case I was trying to use the emit() method to push out a prop: MyObject[].

At first I ""resolved"" the issue by changing my MyObject properties by defining them as optional ?:, but later on we realized the fault was that in my EventEmitter initialization I forgot to add [] after MyObject

BEFORE

  @Output() output = new EventEmitter<MyObject>();

AFTER

  @Output() output = new EventEmitter<MyObject[]>();

Upvotes: 0

Lorenzo Dominguez
Lorenzo Dominguez

Reputation: 36

I've seen the tutorial you are following, the fix was posted early in the first lecture when installing nodeJs.

You'll need to go into the tsconfig.json file of your project and set "strict" to false, then save, close the ng server and re-compile.

Upvotes: 2

Meghana
Meghana

Reputation: 1

Change the configuration in tsconfig.json disable "strict" : true; and enable "noImplicitAny": false

Upvotes: 0

Petros
Petros

Reputation: 1607

Try adding types..

storedPosts: any[] = [];
  OnPostAdded(post: any){
    this.storedPosts.push(post);
  }

As you are using typescript; you should consider providing types for your data instead of any. You can create an interface to describe the data; this will also make the code readable for other developers

Upvotes: 1

Related Questions