question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Angular - Argument of type 'Event' is not assignable to parameter of type 'CustomEvent<XXX>'.

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

Wrong definition type breaks the app.

Expected Behavior

Having the right definition type

Steps to Reproduce

  • Create a new ionic project: ionic start test-ionic
    • Framework: Angular
    • Starter template: tabs

Copy/paste the code sample (html and ts) from https://ionicframework.com/docs/api/reorder-group in tab1.page.(html|ts). Then in your IDE you’ll notice the given error:

Argument of type ‘Event’ is not assignable to parameter of type ‘CustomEvent<ItemReorderEventDetail>’. Type ‘Event’ is missing the following properties from type ‘CustomEvent<ItemReorderEventDetail>’: detail, initCustomEventngtsc(2345)

Try to build the app: ionic build --prod, it won’t build (same error).

It does this with other events as well…

Same issue occurs on ionic 6 rc3

Code Reproduction URL

https://github.com/JumBay/ionic-event-type-issue

Ionic Info

$ ionic info [WARN] Error loading @capacitor/ios package.json: Error: Cannot find module ‘@capacitor/ios/package’

   Require stack:
   - /usr/local/lib/node_modules/@ionic/cli/lib/project/index.js
   - /usr/local/lib/node_modules/@ionic/cli/lib/index.js
   - /usr/local/lib/node_modules/@ionic/cli/index.js
   - /usr/local/lib/node_modules/@ionic/cli/bin/ionic

[WARN] Error loading @capacitor/android package.json: Error: Cannot find module ‘@capacitor/android/package’

   Require stack:
   - /usr/local/lib/node_modules/@ionic/cli/lib/project/index.js
   - /usr/local/lib/node_modules/@ionic/cli/lib/index.js
   - /usr/local/lib/node_modules/@ionic/cli/index.js
   - /usr/local/lib/node_modules/@ionic/cli/bin/ionic

Ionic:

Ionic CLI : 6.18.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.9.1 @angular-devkit/build-angular : 12.1.4 @angular-devkit/schematics : 12.1.4 @angular/cli : 12.1.4 @ionic/angular-toolkit : 4.0.0

Capacitor:

Capacitor CLI : 3.3.2 @capacitor/android : not installed @capacitor/core : 3.3.2 @capacitor/ios : not installed

Utility:

cordova-res : not installed globally native-run : 1.5.0

System:

NodeJS : v14.18.1 (/usr/local/bin/node) npm : 6.14.15 OS : macOS Monterey

Additional Information

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
DeezCashewscommented, Feb 14, 2022

Temporary solution if you want to leave strict template type checking enabled is to wrap $event in $any(). Example:

TS:

  doReorder(ev: CustomEvent<ItemReorderEventDetail>) {
    console.log('Dragged from index', ev.detail.from, 'to', ev.detail.to);
  }

Template:

<ion-reorder-group (ionItemReorder)="doReorder($any($event))" disabled="true">
2reactions
sean-perkinscommented, Jun 23, 2022

@hakimio no, the PR to address this issue is still in a draft state: #25502.

With the changes required to resolve the issue, I’m giving the community plenty of time to test with the dev-build and help verify, before merging and releasing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found