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)

Most upvoted comments

Hi @devna13, I tested installation of tns-platform-declarations on my side, however was unable to reproduce this behavior. Could you change typescript version to 2.0.10 in your project package.json file, remove node_modules, platforms and hooks folder, then try to rebuild your project with tns 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

"include": [
          "typings-i386/*",
          "Interop.d.ts"
        ]

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

"include": [
        "typings-i386/*",
        "Interop.d.ts"
    ]

in your tsconfig.json file. You could also review below given summarized description, how to install tns-platform-declarations.

1.install the definition files npm i tns-platform-declarations@next

  1. open references.d.ts in your main app directory and add the following
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es2016.d.ts" />

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

3, open tsconfig.json in your app and add the support for ES2016 and the missing includes.

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "experimentalDecorators": true,
        "lib": [
            "es2016"
        ]
    },
    "include": [
          "typings-i386/*",
          "Interop.d.ts"
        ]

}

Hope this helps.