zoukankan      html  css  js  c++  java
  • 为 NativeScript 项目添加 iOS / Android 平台 API 的智能感知

    使用 NativeScript ,我们可以很容易的调用平台的原生 API,在开发过程中,我们可以添加这些 API 的 d.ts 文件来提供智能感知,帮助我们更方便的构建媲美原生的 APP。

    首先通过 npm 下载 d.ts 文件

    npm i --save-dev tns-platform-declarations
    

    然后添加引用,修改项目根目录下的 reference.d.ts 内容设置为下面的代码:

    /// <reference path="./node_modules/tns-core-modules/tns-core-modules.es6.d.ts" />
    
    /// <reference path="node_modules/tns-platform-declarations/android/android17.d.ts" />
    /// <reference path="node_modules/tns-platform-declarations/ios/ios.d.ts" />
    

    然后修改 tsconfig.json

    {
        "compilerOptions": {
            "module": "commonjs",
            "target": "es5",
            "experimentalDecorators": true,
            "emitDecoratorMetadata": true,
            "noEmitHelpers": true,
            "noEmitOnError": true,
            "skipLibCheck": true,
            "lib": [
                "es2016"
            ]
        },
        "exclude": [
            "node_modules",
            "platforms",
            "**/*.aot.ts"
        ]
    }
    

    如果你按照官方的描述来配置 reference.d.ts,你可能会在转译 ts 时遇到下面的问题,这时候按照上面的代码来设置即可解决

    node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2300: Duplicate identifier 'UIEvent'.
        
    node_modules/typescript/lib/lib.d.ts(14991,11): error TS2300: Duplicate identifier 'UIEvent'.
    
    node_modules/typescript/lib/lib.d.ts(14997,13): error TS2300: Duplicate identifier 'UIEvent'.
    

    参考:https://github.com/NativeScript/NativeScript/issues/2724

  • 相关阅读:
    docker容器,镜像常用操作
    微信小程序登录状态
    微信小程序登录流程图
    GET和POST可传递的值到底有多大?
    php发送请求
    thinkphp 导入微信小程序加密解密库
    thinkphp 随机获取一条数据
    bootstrap row 行间距
    webstorm es6 语法报错
    Laravel
  • 原文地址:https://www.cnblogs.com/JacZhu/p/6492326.html
Copyright © 2011-2022 走看看