mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
filesystem: Quality-of-life changes
Certain methods always return a specific Entry type. Define more specific callbacks so that typescript can infer when an Entry is a DirectoryEntry or FileEntry, removing the need to explicitly state the type in certain callbacks. Existing code using this definition should not be broken as a result of this change. Signed-off-by: David Li <jiawei.davidli@gmail.com>
This commit is contained in:
@@ -7,7 +7,7 @@ declare function writeDataToLogFile(fileWriter:FileWriterSync): void;
|
||||
|
||||
function useAsyncFS(fs:FileSystem):void {
|
||||
// see getAsText example in [FILE-API-ED].
|
||||
fs.root.getFile("already_there.txt", null, function (f:FileEntry): void{
|
||||
fs.root.getFile("already_there.txt", null, function (f): void{
|
||||
|
||||
// In the example of the specification, there is a following code:
|
||||
//
|
||||
@@ -19,7 +19,7 @@ function useAsyncFS(fs:FileSystem):void {
|
||||
});
|
||||
|
||||
// But now we can also write to the file; see [FILE-WRITER-ED].
|
||||
fs.root.getFile("logFile", {create: true}, function (f:FileEntry): void{
|
||||
fs.root.getFile("logFile", {create: true}, function (f): void{
|
||||
f.createWriter(writeDataToLogFile);
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+23
-3
@@ -197,7 +197,7 @@ interface Entry {
|
||||
* @param successCallback A callback that is called to return the parent Entry.
|
||||
* @param errorCallback A callback that is called when errors happen.
|
||||
*/
|
||||
getParent(successCallback:EntryCallback, errorCallback?:ErrorCallback):void;
|
||||
getParent(successCallback:DirectoryEntryCallback, errorCallback?:ErrorCallback):void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +223,7 @@ interface DirectoryEntry extends Entry {
|
||||
* @param successCallback A callback that is called to return the File selected or created.
|
||||
* @param errorCallback A callback that is called when errors happen.
|
||||
*/
|
||||
getFile(path:string, options?:Flags, successCallback?:EntryCallback, errorCallback?:ErrorCallback):void;
|
||||
getFile(path:string, options?:Flags, successCallback?:FileEntryCallback, errorCallback?:ErrorCallback):void;
|
||||
|
||||
/**
|
||||
* Creates or looks up a directory.
|
||||
@@ -240,7 +240,7 @@ interface DirectoryEntry extends Entry {
|
||||
* @param errorCallback A callback that is called when errors happen.
|
||||
*
|
||||
*/
|
||||
getDirectory(path:string, options?:Flags, successCallback?:EntryCallback, errorCallback?:ErrorCallback):void;
|
||||
getDirectory(path:string, options?:Flags, successCallback?:DirectoryEntryCallback, errorCallback?:ErrorCallback):void;
|
||||
|
||||
/**
|
||||
* Deletes a directory and all of its contents, if any. In the event of an error [e.g. trying to delete a directory that contains a file that cannot be removed], some of the contents of the directory may be deleted. It is an error to attempt to delete the root directory of a filesystem.
|
||||
@@ -307,6 +307,26 @@ interface EntryCallback {
|
||||
(entry:Entry):void;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface is the callback used to look up FileEntry objects.
|
||||
*/
|
||||
interface FileEntryCallback {
|
||||
/**
|
||||
* @param entry
|
||||
*/
|
||||
(entry:FileEntry):void;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface is the callback used to look up DirectoryEntry objects.
|
||||
*/
|
||||
interface DirectoryEntryCallback {
|
||||
/**
|
||||
* @param entry
|
||||
*/
|
||||
(entry:DirectoryEntry):void;
|
||||
}
|
||||
|
||||
/**
|
||||
* When readEntries() succeeds, the following callback is made.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user