NativeScript: tns-platform-declarations 2.3.0 ERROR on build [iOS]
Adding the latest tns-platform-declarations throws with
node_modules/tns-platform-declarations/tns-core-modules/ios/objc-i386/objc!CoreAudio.d.ts(7,13): error TS2403: Subsequent variable declarations must have the sa
me type. Variable 'AudioBuffer' must be of type '{ new (): AudioBuffer; prototype: AudioBuffer; }', but here has type 'StructType<AudioBuffer>'.
node_modules/tns-platform-declarations/tns-core-modules/ios/objc-i386/objc!UIKit.d.ts(4940,15): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/tns-platform-declarations/tns-core-modules/ios/objc-i386/objc!UIKit.d.ts(4940,15): error TS2417: Class static side 'typeof UIEvent' incorrectly ext
ends base class static side 'typeof NSObject'.
Types of property 'alloc' are incompatible.
Type '() => UIEvent' is not assignable to type '() => NSObject'.
Type 'UIEvent' is not assignable to type 'NSObject'.
Property 'accessibilityActivationPoint' is missing in type 'UIEvent'.
node_modules/typescript/lib/lib.d.ts(14781,11): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/typescript/lib/lib.d.ts(14787,13): error TS2300: Duplicate identifier 'UIEvent'.
Also a breaking change to the ios.d.ts path has been introduced and the path now is
/// <reference path="./node_modules/tns-platform-declarations/tns-core-modules/ios/ios.d.ts" />
compared to the path in 2.2.0
/// <reference path="./node_modules/tns-platform-declarations/tns-core-modules/ios.d.ts" />
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 34 (6 by maintainers)
Hey @joshcomley , @SamuelGRwebfab , @corne-de-bruin @bm-software
As a workaround add this to your references.d.ts
and your tsconfig.json should look like this:
The solution above is assuming you are creating NativeScript + Angular-2 application which is using NativeScript 2.4.0 and tns-platform-declarations 2.4.0
Hey @NickIliev
Thanks for the workaround!
Since we are using rxjs: 5.0.0-beta12 we also had to include the following type declares: declare type NodeList = any; declare type HTMLCollection = any; declare type MessageEvent = any; declare type CloseEvent = any; declare type WebSocket = any;
Hey @SamuelGRwebfab can you paste the content of your package.json, tsconfig.json and references.d.ts ? Note that you should have tns-core-modules 2.4.0 as a minimum version for this to work.
We have created sample Angular-2 application which you can use as a reference. In this application, we are using tns-platform-declarations with the solution posted above.
Hopefully, this should resolve the issue.
references.d.ts
Notice how I referenced
tns-core-modules.es6.d.tsNOTtns-core-modules.d.tstsconfig.json
Notice I how I included
"lib": [ "es2016" ]This resolved the issue for me.
@Gerstalexej
I was able to get my TSC to work (and it seems like everything else) by going into the app folder, then in the references.d.ts INSIDE OF THE APP FOLDER not root, change the reference to
/// <reference path="../node_modules/tns-core-modules/tns-core-modules.es2016.d.ts" />Do not add the other references, this should be the only reference in the file.
If I find that this causes any issues i will post an update, hopefully with a fix for what ever issues crop up
This worked for me trying (using nativescript-angular 2.5.2):
Add this line to the file accessing the native API:
/// <reference path="../../node_modules/tns-platform-declarations/ios/ios.d.ts" /> Needed for autocompletion and compilation.Ex.:
My ts.config.json looks like this:
My
references.d.tsstill looks like this:/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" /> Needed for autocompletion and compilation.I am now able to build the app and everything works as expected.
Hey @NickIliev, I’m having the same problem as @SamuelGRwebfab , the workaround didn’t solve the problem. I am NOT using Angular, just regular nativescript+typescript.
This is my package.json
tsconfig.json
references.d.ts
Thanks for the help!
@NickIliev
I just tried this work around and its throwing even more errors (copied your code exactly except i have a reference for firebase as well). My IDE is giving me an error on each declared type saying duplicate identifier. Here is the console error (not all of it)
node_modules/tns-core-modules/weakmap.d.ts(11,13): error TS2403: Subsequent vari able declarations must have the same type. Variable ‘WeakMap’ must be of type ’ WeakMapConstructor’, but here has type ‘new <K, V>() => WeakMap<K, V>’.
Does anyone know how to correctly use the type definitions from NativeScript? I’ve tried every solution offered here and nothing works, always compilation errors like
error TS2304: Cannot find name 'Node'.I’m experiencing the same issue with the upgrade to Nativescript 2.3.0. I’ve discoverd that the compile issues are solved if you the “lib.core.d.ts” and “lib.dom.d.ts” from the tns-core-modules. But still haven’t found a good solution or workaround for this.
@holymp2006 I tried your solution and it worked but only if I put
"outDir": "app"option in my tsconfig.json. Without that option,tns buildcommand fails to compile with multiple Cannot find name ‘X’ errors like:With
"outDir": "app"option I can build and run my project without any errors but VS Code could not find modules references during development (showing an error in the file):This is my tsconfig.json:
How can I solve this?