【问题标题】:NativeScript/TypeScript : cannot find namespace 'android'NativeScript/TypeScript:找不到命名空间“android”
【发布时间】:2018-10-15 22:16:27
【问题描述】:

我的打字稿文件中有以下代码

  const startActivity: android.app.Activity = app.android.startActivity;
  const context: android.content.Context = app.android.context;
  let intent: android.content.Intent;

为什么它显示错误'找不到命名空间'android'。我是否需要安装与原生 android 相关的插件(例如 tns-platform-declarations)

谢谢。

非常感谢您的帮助。

【问题讨论】:

    标签: typescript nativescript


    【解决方案1】:

    是的,你是对的。使用 tns-platform-declarations 并按照它提供的设置进行操作,以便 TypeScript 了解本机 android/ios API。

    安装后,主要是在你的项目根目录下创建一个references.d.ts文件,内容如下:

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

    还请务必注意文档中的这一点:

    d.ts 文件需要大量内存和 CPU。考虑在 tsconfig 文件中添加 skipLibCheck 选项。

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 1970-01-01
      • 2017-02-15
      • 2021-11-18
      • 2021-01-21
      • 1970-01-01
      • 2021-03-01
      • 2021-09-29
      • 1970-01-01
      相关资源
      最近更新 更多