Estoy tratando de hacer una devolución de llamada de animación en angular, y obtuve un error de tipo que se puede suprimir fácilmente con type any . Quiero entender por qué AnimationEvent no es aceptado por mecanografiado.
Mi componente:
import { Component } from '@angular/core'; import { animate, state, style, transition, trigger } from "@angular/animations"; @Component({ selector: 'app-animation-callback', animations: [ trigger('openClose', [ state('open', style({ height: '200px', })), state('closed', style({ height: '100px', })), transition('open <=> closed', [ animate('.1s') ]), ]), ], template: ` <nav> <button (click)="toggle()">Toggle</button> </nav> <div [@openClose]="isOpen ? 'open' : 'closed'" (@openClose.start)="onAnimationEvent($event)" (@openClose.done)="onAnimationEvent($event)" class="open-close-container"> Text </div> `, }) export class AnimationCallbackComponent { isOpen = true; toggle() { this.isOpen = !this.isOpen; } onAnimationEvent(event: AnimationEvent) { } }El error durante la compilación:
error TS2345: Argument of type 'AnimationEvent_2' is not assignable to parameter of type 'AnimationEvent'. (@openClose.done)="onAnimationEvent($event)" ~~~~~~Intente agregar importación en su componente:
import { AnimationEvent } from "@angular/animations";Sin importar, se usa el AnimationEvent nativo de TypeScript, que es un tipo completamente diferente.