NativeScript: Compile errors when using typescript and tns-platform-declarations
I want to make some native API references in my typescript code. I followed the instructions in this stackoverflow answer and although the app builds and the autocomplete is working in VSCode. I get the compile time errors shown below.
Which platform(s) does your issue occur on?
iOS
Please provide the following version numbers that your issue occurs with:
- CLI:2.3.0
- Cross-platform modules: “tns-core-modules”: “^2.4.0-2016-10-19-4474”
- Runtime(s):
“tns-android”: { “version”: “2.3.0” }, “tns-ios”: { “version”: “2.3.0” }
Errors
tns run ios --emulator
Executing before-prepare hook from ..../hooks/before-prepare/nativescript-dev-typescript.js
Found peer TypeScript 2.0.3
node_modules/tns-platform-declarations/ios/objc-i386/objc!CoreAudio.d.ts(7,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'AudioBuffer' must be of type '{ new (): AudioBuffer; prototype: AudioBuffer; }', but here has type 'StructType<AudioBuffer>'.
node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/tns-platform-declarations/ios/objc-i386/objc!UIKit.d.ts(4954,15): error TS2417: Class static side 'typeof UIEvent' incorrectly extends 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(15879,11): error TS2300: Duplicate identifier 'UIEvent'.
node_modules/typescript/lib/lib.d.ts(15885,13): error TS2300: Duplicate identifier 'UIEvent'.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (5 by maintainers)
Hi @devna13, I tested installation of
tns-platform-declarations
on my side, however was unable to reproduce this behavior. Could you changetypescript
version to 2.0.10 in your projectpackage.json
file, removenode_modules
,platforms
andhooks
folder, then try to rebuild your project withtns run <platform_name>
;@tsonevn, that appears to have cracked it. Thank you for your assistance!
@x00 Can you explain more about your case? I’m actually working only for iOS, so no app.gradle file
I figured adding
caused “can’t find module” errors in VSCode. Don’t know why
Hi @ahalls, Thank you for reporting this problem. To avoid the above-given error you should do one more step after you follow the described steps from the StackOverflow question. You should also add the
in your
tsconfig.json
file. You could also review below given summarized description, how to installtns-platform-declarations
.1.install the definition files
npm i tns-platform-declarations@next
references.d.ts
in your main app directory and add the following3, open
tsconfig.json
in your app and add the support forES2016
and the missing includes.Hope this helps.