Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acessing Apache Cordova plugins using Typescript

I am prototyping an A Hybrid Mobile app using Ionic + Angular + Apache Cordova 4.0 using Visual Studio 2003 update 4. I installed the SQLite plugin to access database.

Recommended method to access this plugin is:

var db = window.sqlitePlugin.openDatabase({name: "my.db"});

But I don't have typescript definition for plugin - only Cordova. SO Typescript does not know the sqlitePLugin and its complaining about it.

How do you access Cordova plugin from Typescript code ? I understand I have to somehow extend the basic "window" object ? How to do that ?

Thanks.

like image 595
user1667302 Avatar asked Jan 31 '15 18:01

user1667302


1 Answers

I understand I have to somehow extend the basic "window" object ? How to do that ?

Here you go:

interface Window {
    sqlitePlugin: any;
}

var db = window.sqlitePlugin.openDatabase({name: "my.db"});

Note: TypeScript interfaces are open ended in that their declaration can be re-opened to add members.

like image 102
basarat Avatar answered Sep 25 '22 00:09

basarat