cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

Lack of types for TypeScript

Open lajtobw opened this issue 3 years ago • 0 comments
trafficstars

Bug Report

Problem

What is expected to happen?

Use of Cordova's File, FileReader, and probably other types, while using TypeScript, as normal.

What does actually happen?

Use of TypeScript's File, FileReader, and probably other types, instead of Cordova's. As a result, you have the false impression of using different types. For example, you think File is a Blob, but it is not, since Cordova has a different type with the same name.

Information

It seems there are no types for File, FileReader, and probably more, so TypeScript uses its own types instead of Cordova's.

Command or Code

While working with TypeScript, on VS Code for example, you think all the time that you work with this File:

// typescript/lib/lib.dom.d.ts
interface File extends Blob {
    readonly lastModified: number;
    readonly name: string;
    readonly webkitRelativePath: string;
}

It's important to mention a similar conflict. Some types, like FileSystem, exist both in Cordova and TypeScript:

// typescript/lib/lib.dom.d.ts
interface FileSystem {
    readonly name: string;
    readonly root: FileSystemDirectoryEntry;
}

// cordova-plugin-file/types/index.d.ts
/** This interface represents a file system. */
interface FileSystem {
    /* The name of the file system, unique across the list of exposed file systems. */
    name: string;
    /** The root directory of the file system. */
    root: DirectoryEntry;
}

So you can have situations like this:

// ...
function (fs: FileSystem) {
    ok(fs.root);  // fs.root is a DirectoryEntry, but type system complains about being FileSystemDirectoryEntry
}
// ...

Environment, Platform, Device

I experience the issue during development, but if you ignore the type checking, it works as it should.

Version information

  • node version: 16.15.0
  • cordova-plugin-file version: 7.0.0
  • typescript version: 4.7.2
  • editor: VS Code

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

lajtobw avatar Jun 01 '22 13:06 lajtobw