Getting plugin functions on Typescript

倖福魔咒の 提交于 2019-12-12 20:22:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!