I recently created an Ionic 2 project using Typescript and I cannot use plugins using the object they declare in their tag. If I try, for instance, to use InAppBrowser, which is supposed to be accessible through
cordova.InAppBrowser.open(), I get an error because the global
cordova object is undefined.
InAppBrowser also clobbers
window.open(), and that one works; my guess is because that method already exists. I’ve verified that it is indeed calling the plugin’s version of
open(), and succeeding, so the plugin is loading for sure. To reiterate, the plugin loads, and successfully clobbers
window.open(), and does not successfully clobber
With InAppBrowser, I can work around this issue by using
window.open(), but with the other plugins this bug renders them entirely unusable.
I’ve mentioned my issue in a few other topics, and I don’t seem to be the only one having these difficulties. Someone else noted that
cordova.InAppBrowser.open() doesn’t exist, and another user is struggling with the Social Sharing plugin. I earlier misdiagnosed the issue as all plugins entirely failing to load, but I have ruled that out at this point.
So, does anyone know what the problem is? I suspect a bug in Ionic 2, or the latest version of the starter code.
I do not believe the cause is a lack of
.d.ts files. I have created them for each of these plugins, and the compile-time errors go away, but the run-time errors do not. Besides, my understanding is that type errors at compile time are unimportant; if I don’t include the
.d.ts file for a working plugin, it spits out errors at compile time, but works at runtime.