Using TypeScript with PhoneGap/Cordova Plugins -
i'm running bit of roadblock start using google analytics cordova plugin i'm composing of javascript assets in typescript. here example of specific problem i'm having:
window.plugins.googleanalyticsplugin.starttrackerwithaccountid("ua-xxxxxxx-x");
typescript balks @ window.plugins
, throwing compilation error:
the property 'plugins' not exist on value of type 'window'.
and makes complete sense. however, can't around using declare var window;
statement, creates duplicate identifier window.
step 1 extend window
interface, can this:
interface window { plugins: any; }
this mean no compiler errors, unless extend definition means no auto-completion. line work:
window.plugins.googleanalyticsplugin.starttrackerwithaccountid("ua-xxxxxxx-x");
to take things notch , auto-completion (and spellings checked too) can use extended version of definition.
interface googleanalyticsplugin { starttrackerwithaccountid(accountid: string): void; } interface plugins { googleanalyticsplugin: googleanalyticsplugin; } interface window { plugins: plugins; }
Comments
Post a Comment