-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: ionRefresh emits object typed as RefresherEventDetail but actually emits RefresherCustomEvent #26747
Comments
Thanks for the report. The correct type is {
target: ...,
detail: {
complete: () => { ... }
},
...
} Both edit: |
So that means the refresher.tsx code needs to be changed? from possibly giving a type error on line 701?
At least this would solve the typings issue. (and help generating the right typings in ionic-svelte using |
No, the code is correct. We ship a |
Ok - will put two code examples here in coming minutes. Angular and Svelte - with the errors. For me to understand what I need to fix in the code and/or the ionic-svelte typings definition which now says. |
Do you have a sample app I can try? It's hard to understand what is going on here from only screenshots.
This is an issue with our Angular compatibility: #24245. The reason is the event type is assumed to always be |
Sorry about that - svelte I reckon, given that the angular part is a known issue Svelte: https://github.com/Tommertom/ionicrefresher +page.svelte in /route |
Thanks! The types that Ionic Svelte is generating appear to be wrong. In interface IonRefresher {
...,
"on:ionRefresh"?: (event: RefresherEventDetail) => void;
} This should be The |
Ok - thx for the debugging - just for my info - you expect this to be happening other places as well? It is the first type I am seeing this issue. Or as you say - it is happening everywhere so I need to wrap all events in Now - I am quite bluntly using the core.json data to generate this type. So for this situation it was
Thx again - will close the issue. |
Yes, every event emitted from Ionic components is a |
Nice - thx- will change the script and generate new typings. |
The team also looked at the Ionic Svelte source. The issue appears to be around here: https://github.com/Tommertom/svelte-ionic-npm/blob/main/scripts/generate.js#L242-L251 Should minimally be: But ideally you can do the following to get the (This is psuedo-code and assumes Svelte does not do something different with events) |
ok - thx- that I will include in the generate script. And clean up the repo as there are a few experimental generator scripts. Appreciate all the help! |
I am now generating for all events What is
|
new version published - and scripts updated - generator.js is the go-to script |
|
Sorry to bother again - but I am now a bit confused what to do in the demo repo: This will not generate any typescript issue(as I am using RefresherCustomEvent), but will be friction for developers to find as it is not specified in the docs nor can be inferred from the type definition in the IDE or typings file:
Whereas if you use ev:RefresherEventDetail, there is a typescript error on
|
|
Error- The If this is the only event where this is happening, I am happy to overrule |
Yes, this is why You don't necessarily need to use these custom event interfaces. As I mentioned in #26747 (comment), you could do something like |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
Current Behavior
The tsx to ion-refresher specifies it emits RefresherEventDetails:
@Event() ionRefresh!: EventEmitter<RefresherEventDetail>;
this exposes the
complete
method to the user to complete the refreshing.So this would mean something like this needs to work:
(pseudo code)
on:ionRefresh={refresher}
whererefresher
would be likefunction refresher(ev:RefresherEventDetails) {.. ev.complete() }
This code complies to typings, but will give a runtime error as the correct way is
ev.target.complete()
.But that that will give a typings error in the IDE.
Changing to
function refresher(ev: RefresherCustomEvent) {.. ev.target.complete() }
will fix this, but gives IDE errors because of type mismatch.The workaround is to remove typings or use any keyword.
Notably the docs state that you must use
complete()
where the code example saytarget.complete()
. So if you take things very literally, it could become confusing and error prone.(meaning you need to bind to the ion-refresher component and then call its
complete()
method)(take the event object and call
ev.target.complete()
.So possibly a documentation improvement (happy to do PR) but maybe a code fix in refresher.tsx?
Expected Behavior
No runtime issue when calling
ev.complete()
or no typings error when using type on theionRefresh
event.Steps to Reproduce
See above
Code Reproduction URL
None available - the code examples on ion-refresher have the issue
Ionic Info
Occurs in angular project:
Ionic:
Ionic CLI : 6.20.6 (C:\Users\xxxx\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.5.2
@angular-devkit/build-angular : 15.1.4
@angular-devkit/schematics : 15.1.4
@angular/cli : 15.1.4
@ionic/angular-toolkit : 6.1.0
Capacitor:
Capacitor CLI : 4.6.3
@capacitor/android : not installed
@capacitor/core : 4.6.3
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v16.14.2 (C:\Program Files\nodejs\node.exe)
npm : 8.10.0
OS : Windows 10
And also ionic svelte (no ionic info)
Additional Information
https://discordapp.com/channels/520266681499779082/1049388501629681675/1072243939635122187
#20221
The text was updated successfully, but these errors were encountered: