-
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
refactor: use capacitor types for native plugins #27755
Conversation
Run & review this pull request in StackBlitz Codeflow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to test the dev build on my end too, but some final comments on the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and it works great! Tested with the datetime wheel picker for haptics as well as when Capacitor (but not the plugins) are available. I left a couple comments, but this is good to merge once those are addressed.
Issue number: Internal
What is the current behavior?
Ionic currently detects and uses Capacitor APIs for different plugins (haptics, status bar and keyboard). This implementation does not have type safety and can result in unexpected behaviors.
What is the new behavior?
@capacitor/core
,@capacitor/keyboard
,@capacitor/haptics
and@capacitor/status-bar
as dev dependencies. These should only be used withimport type { }
.getCapacitor()
function for interacting with thewindow.Capacitor
object through a typed object.How does it work?
The idea is we want the type safety from the Capacitor packages, without directly bundling that source code within Ionic Framework. This means we use the Capacitor deps where a type is needed, but clone any enums where a value is referenced. If a Capacitor dep changes the supported values, Typescript will fail to compile and that will signal to use to update our enum values to match any changes.
Does this introduce a breaking change?
Other information
Dev-build:
7.1.2-dev.11688696027.1c4d4ad1
Tested against a demo app for some of the core behavior: https://github.com/sean-perkins/capacitor-ionic-plugins-demo