cordova-plugin-file
cordova-plugin-file copied to clipboard
Fix type misaligments in newer TypeScript versions
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected] for the project I'm working on.
Apparently the type definitions provided by this plugin don't work with newer TypeScript versions (I'm using 4.8). The result is a mismatch of the types with the TypeScript internal types, causing a Subsequent property declarations must have the same type error.
Here is the diff that solved my problem by align the types to TypeScript's ones:
diff --git a/node_modules/cordova-plugin-file/types/index.d.ts b/node_modules/cordova-plugin-file/types/index.d.ts
index 469d862..c8b1b86 100644
--- a/node_modules/cordova-plugin-file/types/index.d.ts
+++ b/node_modules/cordova-plugin-file/types/index.d.ts
@@ -44,9 +44,9 @@ interface Window {
/** This interface represents a file system. */
interface FileSystem {
/* The name of the file system, unique across the list of exposed file systems. */
- name: string;
+ readonly name: string;
/** The root directory of the file system. */
- root: DirectoryEntry;
+ readonly root: FileSystemDirectoryEntry;
}
/**
This issue body was partially generated by patch-package.
Doing so seems to break the examples in the repo (And I'm assuming that the plugin in general), since FileSystemDirectoryEntry is not assignable to DirectoryEntry
I'd suggest just renaming the interface to something that doesn't coincide with the global new one;
diff --git a/index.d.ts b/index.d.ts
--- a/index.d.ts
+++ b/index.d.ts
@@ -18,5 +18,5 @@ interface Window {
type: LocalFileSystem,
size: number,
- successCallback: (fileSystem: FileSystem) => void,
+ successCallback: (fileSystem: FileSystemCordova) => void,
errorCallback?: (fileError: FileError) => void): void;
/**
@@ -43,5 +43,5 @@ interface Window {
/** This interface represents a file system. */
-interface FileSystem {
+interface FileSystemCordova {
/* The name of the file system, unique across the list of exposed file systems. */
name: string;
@@ -64,5 +64,5 @@ interface Entry {
fullPath: string;
/** The file system on which the entry resides. */
- filesystem: FileSystem;
+ filesystem: FileSystemCordova;
nativeURL: string;
/**
@ajuanjojjj Thanks, that sound's good :+1: