Step one is to extend the Window interface, which you can do as follows:
interface Window { plugins: any; }
This does not mean compiler errors, but if you do not expand the definition, it means no automatic completion. Now this line will work:
window.plugins.googleAnalyticsPlugin.startTrackerWithAccountID("UA-xxxxxxx-x");
You can use this extended version of the definition to make something more visible and get automatic completion (and so that your checks are also verified).
interface GoogleAnalyticsPlugin { startTrackerWithAccountID(accountId: string): void; } interface Plugins { googleAnalyticsPlugin: GoogleAnalyticsPlugin; } interface Window { plugins: Plugins; }
source share