首页 > 解决方案 > Nativescript 6代码共享项目和tns-platform-declarations:编译时出错

问题描述

我在此页面之后创建了一个新的 Nativescript 代码共享项目:

https://docs.nativescript.org/angular/code-sharing/creating-a-new-project

ng new -c=@nativescript/schematics TestProject --shared --style=scss

然后我tns-platform-declarations在此页面中添加了以下步骤:

https://docs.nativescript.org/core-concepts/accessing-native-apis-with-javascript

但是当我尝试使用 iOS 特定的类(如 NSString)时,它仍然给我一个编译错误:

error TS2552: Cannot find name 'NSString'.

在旧的标准 NS 项目中它正在工作,所以它可能与代码共享有关,我做错了什么?

这是一个示例项目:https ://www.dropbox.com/s/66ve80jif3bf0qk/TestProject.zip?dl=0

标签: nativescriptnativescript-angularcode-sharing

解决方案


我遇到了和你描述的一样的问题。VS Code 按预期识别类型,但构建失败。

我通过在tsconfig.tns.json中包含reference.d.ts解决了这个问题。

"files": [
"./reference.d.ts",
"src/main.tns.ts"
]

推荐阅读