apache / apache/cordova-plugin-file
Lack of types for TypeScript
- Dominant language
- JavaScript
- Stars
- 744
- Forks
- 754
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 1
Description
# 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`:
```ts
// 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:
```ts
// 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:
```ts
// ...
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
Contributor guide
Research direction
Start with cordova-plugin-file/types/index.d.ts and compare its File, FileReader, and FileSystem declarations with TypeScript's DOM declarations. Check the example involving FileSystem.root, then verify that Cordova code receives the intended types without TypeScript conflicts; done means the relevant plugin types are present and the example type-checks correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- developer-experience, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100