Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
error TS2345: Argument of type 'Event' is not assignable to parameter of type 'IPokemon'

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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

  • not: make sure that $event has the appropriate form, or
  • if yes: you can add $event as unknown as IPokemon in your function call
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda