在Typescript上获取插件函数 [英] Getting plugin functions on Typescript
本文介绍了在Typescript上获取插件函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个typescript文件中使用一些cordova插件函数,但我不能构建文件。想象一下,我想访问设备平台和模型。有人可以帮我这个吗?我应该为插件的js文件上的每个函数创建接口吗?
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?
提前感谢!
推荐答案
已有定义: 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;
您只需引用此文件(使用 ///< reference
comment),然后您可以:
You simply reference this file (using ///<reference
comment) and then you can do:
console.log(device.model,device.platform);
这篇关于在Typescript上获取插件函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文