Closed sneko closed 5 years ago
Hi @mlynch @jcesarmobile 😃
Is it a normal behavior?
Thank you,
Someone named thesayyn
on Slack proposes me to use the following to avoid the Object is possibly 'undefined'
error:
let app: AppPlugin = plugins.AppPlugin!;
It works yeah, but it seems really painful instead of just extracting the import like const { StatusBar, XXXX, XXXX, XXXX } = Plugins;
I would like to understand why the Capacitor TypeScript interface for PluginRegistry is like that:
interface PluginRegistry {
Accessibility?: AccessibilityPlugin;
App?: AppPlugin;
BackgroundTask?: BackgroundTaskPlugin;
Browser?: BrowserPlugin;
Camera?: CameraPlugin;
Clipboard?: ClipboardPlugin;
Device?: DevicePlugin;
Filesystem?: FilesystemPlugin;
Geolocation?: GeolocationPlugin;
Haptics?: HapticsPlugin;
Keyboard?: KeyboardPlugin;
LocalNotifications?: LocalNotificationsPlugin;
Modals?: ModalsPlugin;
Motion?: MotionPlugin;
Network?: NetworkPlugin;
Photos?: PhotosPlugin;
PushNotifications?: PushNotificationsPlugin;
Share?: SharePlugin;
SplashScreen?: SplashScreenPlugin;
StatusBar?: StatusBarPlugin;
Storage?: StoragePlugin;
Toast?: ToastPlugin;
WebView?: WebViewPlugin;
}
Why all plugins are optional? They are embedded in the Capacitor package...
I'm still hoping an answer 😄
Thank you,
We talked a bit about it and don't really have a solution right now, but in theory this is something we could fix. It's not a priority but we'll leave this open.
Ok thank you for the answer, do not hesitate to update this issue when a decision will be taken 😀
This has been fixed by #1507.
Thanks @simonhaenisch! closing
Hi!
I'm using TypeScript 3.0.3 and while using your plugins it's pretty annoying because I need to wrap them inside "if/else" statements to avoid this error;
Object is possibly 'undefined'
Here an example of my code:
Note: the error is for the
StatusBar.setStyle
How do you manage that? Seems really repetitive to write if/else each time I need to use these plugins 😢
Thank you,