Problem with Typings for Cordova


I want to use the “cordova-plugin-filetransfer”.

I added this plugin to my ionic 2 app:

ionic plugin add cordova-plugin-file-transfer --save

And also I have imported the correpondings typings:

typings install dt~cordova --save --global
typings install dt~cordova/plugins/filesystem --save --global
typings install dt~cordova/plugins/filetransfer --save --global

But when I try to use “cordova” or “FileTransfer” the Angular 2 compiler (ngc) gives me errors:

Cannot find name 'cordova'
Cannot find name 'FileTransfer'

This error can be replicated using the “blank” template from ionic 2:

ionic start Demo blank --v2
ionic plugin add cordova-plugin-file-transfer --save
ionic plugin platform add android

Modifying the “home.ts”

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';

    selector: 'page-home',
    templateUrl: 'home.html'
export class HomePage {

    constructor(public platform: Platform, public navCtrl: NavController) {
        let path: string = "";
        if ("android")) path = cordova.file.externalDataDirectory;
        else if ("ios")) path = cordova.file.documentsDirectory;
        else if ("windows")) path = cordova.file.dataDirectory;

        const fileTransfer = new FileTransfer();


ionic build android

The output is something like:

[12:19:37]  ngc started ...                                                                                                                         
[12:19:38]  copy finished in 216 ms                                                                                                                 
[12:19:38]  lint started ...                                                                                                                        
[12:19:40]  tslint: C:/Datos/Proyectos/Pruebas/Demo/src/pages/home/home.ts, line: 16                                                                
            Unused variable: 'fileTransfer'                                                                                                         
      L16:  const fileTransfer = new FileTransfer();                                                                                                
[12:19:40]  lint finished in 2.52 s                                                                                                                 
[12:19:53]  Error: Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:12:49                                                           
[12:19:53]  Cannot find name 'cordova'.                                                                                                             
[12:19:53]  Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:13:50                                                                  
[12:19:53]  Cannot find name 'cordova'.                                                                                                             
[12:19:53]  Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:14:54                                                                  
[12:19:53]  Cannot find name 'cordova'.                                                                                                             
[12:19:53]  Error at C:/Datos/Proyectos/Pruebas/Demo/.tmp/pages/home/home.ts:16:34                                                                  
[12:19:53]  Cannot find name 'FileTransfer'.                                                                                                        
[12:19:53]  ngc failed                                                                                                                              
[12:19:53]  ionic-app-script task: "build"                                                                                                          
[12:19:53]  Error: Error

Any idea how to use those typings? Do I have to configure something?


It’s easier to use Ionic Native, it does wrap the Transfer plugin as well. And no need to install any additional typings.


But Ionic Native Transfer is not working as I expect. :confused:

I’m using Transfer to download a bunch of files from a server.

If I do a loop, to download file by file, the download method from transfer doesn’t resolves the promise when a file has finished downloading, but when it has started to download.

This causes that the loop starts a big amount of download “threads”. This is that I want to solve. For this is that I wanted to use cordova filetransfer plugin.

How can I “check” if a file has finished downloading using Transfer from ionic native?


That’s weird. Haven’t actually used that plugin, I just thought you didn’t know about Ionic Native.

If you want to use the Cordova plugin directly you could always add some type declarations manually to your code, like

declare var cordova: any;
declare var FileTransfer: any;


I’m getting same problem using typescript with 2.0.0-rc.0. I’ve run the following…

ionic plugin add cordova-plugin-file
typings install dt~cordova --save --global
typings install dt~cordova/plugins/filesystem --save --global

Any help?