【问题标题】:Getting plugin functions on Typescript在 Typescript 上获取插件功能
【发布时间】:2014-04-28 20:19:06
【问题描述】:

我正在尝试在打字稿文件上使用一些 cordova 插件功能,但我无法构建文件。想象一下,我想访问设备平台和模型。有人可以帮我弄这个吗?我应该为插件的js文件上的每个函数创建接口吗?

提前致谢!

【问题讨论】:

    标签: cordova typescript cordova-3 cordova-plugins


    【解决方案1】:

    已经有定义: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 注释),然后您就可以这样做:

    console.log(device.model,device.platform);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-24
      • 2019-07-09
      • 2011-05-20
      • 2015-07-28
      • 1970-01-01
      • 1970-01-01
      • 2020-08-14
      • 2021-10-19
      相关资源
      最近更新 更多