Nativescript 6 code sharing project and tns-platform-declarations: error during compilation

105 Views Asked by At

I've created a new Nativescript Code Sharing Project following this page:

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

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

Then I've added the tns-platform-declarations following the steps in this page:

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

But still when I try to use iOS specific classes (like NSString) it gives me an error on compilation:

error TS2552: Cannot find name 'NSString'.

In the old standard NS project it was working so it's possibly something related to the code sharing, what am I doing wrong?

This is a sample project: https://www.dropbox.com/s/66ve80jif3bf0qk/TestProject.zip?dl=0

1

There are 1 best solutions below

0
Johan Drott On BEST ANSWER

I had the same problem as you described. VS Code recognized the typings as expected but the build failed.

I solved the issue by including reference.d.ts in tsconfig.tns.json.

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