Running this code :
<app-pokemon-form *ngIf="showPokemonForm" (newPokemonEvent)="addNewPokemon($event)"
(pokemonFormClose)="pokemonFormClose($event)"
[pokemon]="currentPokemon"></app-pokemon-form>
Causes an error :
error TS2345: Argument of type 'Event' is not assignable to parameter of type 'IPokemon'.
Here is the TypeScript File:
addNewPokemon(newPokemon: IPokemon): void {
console.log('adding new pokemon ' + JSON.stringify(newPokemon));
this.pokemonService.addPokemon({ ...newPokemon })
.subscribe({
next: pokemon => {
console.log(JSON.stringify(pokemon) + ' has been added');
this.message = "new pokemon has been added";
},
error: (err) => this.message = err
});
And here is the pokemon model itself:
export interface IPokemon {
_id: string,
Name: string,
Generation: Number,
Type: string
}
Any Help Would Be Greatly Appreciated
Since your argument $event is of type Event, meaning it does not (necessarily) have the form of
interface IPokemon {
_id: string,
Name: string,
Generation: number,
Type: string
}
you cannot pass $event to your addPokemon method.
You can check the form of the $event parameter if it matches with the IPokemon interface and if
$event has the appropriate form, or$event as unknown as IPokemon in your function call