You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2022/06/01 13:00:27 UTC

[GitHub] [cordova-plugin-file] lajtomekadimon opened a new issue, #524: Lack of types for TypeScript

lajtomekadimon opened a new issue, #524:
URL: https://github.com/apache/cordova-plugin-file/issues/524

   # 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
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   
   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
   <!-- What command or code is needed to reproduce the problem? -->
   
   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
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   
   I experience the issue during development, but if you ignore the type checking, it works as it should.
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   
   - node version: 16.15.0
   - cordova-plugin-file version: 7.0.0
   - typescript version: 4.7.2
   - editor: VS Code
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org