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)

Most upvoted comments

Hey @joshcomley , @SamuelGRwebfab , @corne-de-bruin @bm-software

As a workaround add this to your references.d.ts


/// <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" 

declare type Location = any;
declare type Node = any;
declare type Document = any;
declare type History = any;
declare type HTMLElement = any;
declare type HTMLStyleElement = any;
declare type KeyboardEvent = any;
declare type Element = any;
declare type DocumentFragment = any;
declare type Text = any;
declare type HTMLDocument = any;
declare type HTMLAnchorElement = any;
declare type Comment = any;
declare type MouseEvent = any;
declare type HTMLInputElement = any;
declare type HTMLScriptElement = any;

and your tsconfig.json should look like this:

{
    "compilerOptions": {
        "noEmitOnError": true,
        "noEmitHelpers": true,
        "sourceMap": true,
        "target": "es5",
        "module": "commonjs",
        "declaration": false,
        "noImplicitAny": false,
        "noImplicitUseStrict": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "pretty": true,
        "lib": [
            "es2016"
        ]
    },
    "exclude": [
        "node_modules",
        "platforms"
    ]
}

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

/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es6.d.ts" /> 

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

declare type FormData = any;
declare var FormData;
declare type Blob = any;
declare var Blob;

Notice how I referenced tns-core-modules.es6.d.ts NOT tns-core-modules.d.ts

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "sourceMap": true,
        "experimentalDecorators": true,
        "lib": [
            "es2016"
        ],
        "emitDecoratorMetadata": true,
        "noEmitHelpers": true,
        "noEmitOnError": true
    },
    "exclude": [
        "node_modules",
        "platforms"
    ]
}

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.:

/// <reference path="../../node_modules/tns-platform-declarations/ios/ios.d.ts" /> Needed for autocompletion and compilation.

class UIImagePickerControllerDelegateImplementation extends NSObject implements UIImagePickerControllerDelegate {
  static ObjCProtocols = [UIImagePickerControllerDelegate];

  static new(): UIImagePickerControllerDelegateImplementation {
    return <UIImagePickerControllerDelegateImplementation>super.new();
  }
}

My ts.config.json looks like this:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noImplicitUseStrict": true,
        "noEmitHelpers": true,
        "declaration": false,
        "removeComments": false,
        "noEmitOnError": false,
        "noImplicitAny": false,
        "noLib": false
    },
    "exclude": [
        "node_modules",
        "platforms"
    ]
}

My references.d.ts still 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


> {
> 
>   "name": "tuerknecht",
>   "version": "1.0.0",
>   "description": "A IoS and Android app for managing acccess to your home via the *Türknecht*.",
>   "repository": {
>     "type": "git",
>     "url": "https://gitlab.com/alexej.gerstmaier/Tuerknecht-nativescript.git"
>   },
>   "keywords": [
>     "Türknecht"
>   ],
>   "author": "Alexej Gerstmaier <alexej@lackey.com> (http://lackey.eu)",
>   "license": "Proprietary",
>   "bugs": {
>     "url": "https://gitlab.com/alexej.gerstmaier/Tuerknecht-nativescript.git"
>   },
>   "homepage": "https://lackey.eu",
>   "nativescript": {
>     "id": "com.quonux.tuerknecht",
>     "tns-ios": {
>       "version": "2.6.0-2017-1-10-1"
>     },
>     "tns-android": {
>       "version": "2.4.1"
>     }
>   },
>   "dependencies": {
>     "email-validator": "^1.0.7",
>     "everlive-sdk": "^1.8.1",
>     "json-stringify-safe": "^5.0.1",
>     "knock-knock-jokes": "^1.7.0",
>     "moment": "^2.17.1",
>     "nativescript-drop-down": "^1.5.1",
>     "nativescript-floatingactionbutton": "^2.2.7",
>     "nativescript-push-notifications": "0.0.19",
>     "nativescript-social-share": "^1.3.1",
>     "tns-core-modules": "^2.4.4"
>   },
>   "devDependencies": {
>     "babel-traverse": "6.10.4",
>     "babel-types": "6.11.1",
>     "babylon": "6.8.2",
>     "lazy": "1.0.11",
>     "nativescript-dev-typescript": "^0.3.5",
>     "tns-platform-declarations": "^2.4.4",
>     "typescript": "^2.0.10"
>   }
> }
> 

tsconfig.json

{ “compilerOptions”: { “module”: “commonjs”, “target”: “es5”, “sourceMap”: true, “experimentalDecorators”: true, “emitDecoratorMetadata”: true, “noEmitHelpers”: true, “noEmitOnError”: true }, “exclude”: [ “node_modules”, “platforms” ] }

references.d.ts


<reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" /> 
 <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
<reference path="./node_modules/tns-platform-declarations/android.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>’.

28     readonly size: number;
                ~~~~

node_modules/typescript/lib/lib.es2015.collection.d.ts(28,14): error TS2687: All
 declarations of 'size' must have identical modifiers.


31 interface MapConstructor {
             ~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.es2015.collection.d.ts(31,11): error TS2300: Dup
licate identifier 'MapConstructor'.


65     readonly size: number;
                ~~~~

node_modules/typescript/lib/lib.es2015.collection.d.ts(65,14): error TS2687: All
 declarations of 'size' must have identical modifiers.


68 interface SetConstructor {
             ~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.es2015.collection.d.ts(68,11): error TS2300: Dup
licate identifier 'SetConstructor'.


28     readonly iterator: symbol;
                ~~~~~~~~

node_modules/typescript/lib/lib.es2015.iterable.d.ts(28,14): error TS2687: All d
eclarations of 'iterator' must have identical modifiers.


33     value: T;
       ~~~~~

node_modules/typescript/lib/lib.es2015.iterable.d.ts(33,5): error TS2687: All de
clarations of 'value' must have identical modifiers.


118 interface MapConstructor {
              ~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.es2015.iterable.d.ts(118,11): error TS2300: Dupl
icate identifier 'MapConstructor'.


135 interface SetConstructor {
              ~~~~~~~~~~~~~~

node_modules/typescript/lib/lib.es2015.iterable.d.ts(135,11): error TS2300: Dupl
icate identifier 'SetConstructor'.


76     readonly prototype: Promise<any>;
                ~~~~~~~~~

node_modules/typescript/lib/lib.es2015.promise.d.ts(76,14): error TS2687: All de
clarations of 'prototype' must have identical modifiers.


33     readonly prototype: Symbol;
                ~~~~~~~~~

node_modules/typescript/lib/lib.es2015.symbol.d.ts(33,14): error TS2687: All dec
larations of 'prototype' must have identical modifiers.

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 build command fails to compile with multiple Cannot find name ‘X’ errors like:

node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(11,26): error TS2304: Cannot find name 'Node'.
node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(12,21): error TS2304: Cannot find name 'Node'.
node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(13,21): error TS2304: Cannot find name 'Node'.
node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(14,16): error TS2304: Cannot find name 'Node'.
...
[many many other]

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):

immagine

This is my tsconfig.json:

{
    "compilerOptions": { 
        "outDir": "app", 
        "module": "commonjs", 
        "target": "es6" ,
        "inlineSourceMap": true, 
        "removeComments": false, 
        "experimentalDecorators": true, 
        "emitDecoratorMetadata": true, 
        "noEmitHelpers": true,
        "noEmitOnError": true, 
        "noLib": false, 
        "lib": [ "es2016" ] 
    }, 
    "exclude": [ 
        "node_modules", 
        "platforms" 
    ] 
}

How can I solve this?