问题
I am trying to use some cordova plugins functions on a typescript file but i can't build the file. Imagine that I want to access the device platform and model. Can someone help me with this? Should I create interfaces for every function on js files of the plugin?
Thanks in advance!
回答1:
There are already definitions for that : https://github.com/borisyankov/DefinitelyTyped/blob/master/cordova/plugins/Device.d.ts
interface Device {
/** Get the version of Cordova running on the device. */
cordova: string;
/**
* The device.model returns the name of the device's model or product. The value is set
* by the device manufacturer and may be different across versions of the same product.
*/
model: string;
/** device.name is deprecated as of version 2.3.0. Use device.model instead. */
name: string;
/** Get the device's operating system name. */
platform: string;
/** Get the device's Universally Unique Identifier (UUID). */
uuid: string;
/** Get the operating system version. */
version: string;
}
declare var device: Device;
You simply reference this file (using ///<reference
comment) and then you can do:
console.log(device.model,device.platform);
来源:https://stackoverflow.com/questions/23339740/getting-plugin-functions-on-typescript