在 NativeScript 中访问 Android 包时出现问题

Having issue while accessing Android packages in NativeScript

documentation 所示:

The Android packages are available in the JavaScript/TypeScript global context and are the entry point for accessing Android APIs. Think of them as of TypeScript/C# namespaces, or the way to access sets of classes. For example, the android.view package grants access to classes like android.view.View - the base of all view elements in Android.

但是,当我尝试访问任何包时,出现以下错误:

Error: Cannot find name 'android'

我不知道这里出了什么问题,也许文档已经过时或者我遗漏了什么。如果你知道请告诉我请告诉我我可以解决这个问题。

在使用 TypeScript 时(即使是普通的 JavaScript,如果你想要原生 API 的智能感知)你需要有明确的声明(通常来自带有 *.d.ts 扩展名的类型文件) .在同一篇文档文章中,您提到了

Note: To have access and Intellisense for the native APIs with NativeScript + TypeScript or NativeScript + Angular projects, you have to add a dev dependency to tns-platform-declarations. More details about accessing native APIs with TypeScript can be found here.

关于如何使用 tns-platform-declarations 的详细说明也可以在 or in the plugin's instructions

中找到