Ionic uses some CustomEvents on its components and with strict TypeScript this might give you console errors like this.
My code was the following:
doReorder(ev: CustomEvent<ItemReorderEventDetail>) {
// Finish the reorder and position the item in the DOM based on
// where the gesture ended. Update the items variable to the
// new order of items
this.items = ev.detail.complete(this.items);
}
The error I got was:
error TS2345: Argument of type 'Event' is not assignable to parameter of type 'Cus
tomEvent<ItemReorderEventDetail>'.
This is due to the behavior of the --strictFunctionTypes
compiler flag added in TypeScript v2.6. A function of type (e: CustomEvent) => void
is no longer considered to be a valid instance of EventListener
, which takes an Event
parameter, not a CustomEvent
.
You can typecast the CustomEvent to make it go away:
doReorder(ev: Event) {
const customEvent = ev as CustomEvent<ItemReorderEventDetail>;
// Finish the reorder and position the item in the DOM based on
// where the gesture ended. This method can also be called directly
// by the reorder group
this.items = customEvent.detail.complete();
}