Add overload that returns promise (#38864)

* Add overload that returns promise

which@2.0.1 supports `Promise`

* Add test for the promise variant

* Add promise overloads with options

* Update which-tests.ts

* Add missing ';'
This commit is contained in:
Khải
2019-10-09 16:19:39 -07:00
committed by Armando Aguirre
parent fd3cd621ae
commit e0e91fbb39
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -13,6 +13,10 @@ declare function which(cmd: string, options: which.AsyncOptions & which.OptionsF
declare function which(cmd: string, options: which.AsyncOptions, cb: (err: Error | null, path: string | Array<string> | undefined) => void): void;
/** Finds the first instance of a specified executable in the PATH environment variable */
declare function which(cmd: string, cb: (err: Error | null, path: string | undefined) => void): void;
/** Finds the first instance of a specified executable in the PATH environment variable */
declare function which(cmd: string, options: which.AsyncOptions & which.OptionsAll): Promise<string[]>;
/** Finds the first instance of a specified executable in the PATH environment variable */
declare function which(cmd: string, options?: which.AsyncOptions & which.OptionsFirst): Promise<string>;
declare namespace which {
/** Finds all instances of a specified executable in the PATH environment variable */
function sync(cmd: string, options: which.Options & which.OptionsAll & which.OptionsNoThrow): Array<string> | null;
+4
View File
@@ -17,6 +17,10 @@ which("cat", {all: true}, (err, paths) => {
}
});
var promise: Promise<string> = which("cat");
var promise1: Promise<string> = which("cat", { all: false });
var promise2: Promise<string[]> = which("cat", { all: true });
var paths = which.sync("cat", {all: true});
for(let path of paths) {
console.log(path);