From ad85bebc6e1d2e60d3e30fa27037cbe4188bb12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Fri, 5 Jun 2020 01:32:41 +0200 Subject: [PATCH] fix(glob): correct return type to mach Glob interface (#45193) This changes detail of lesser known usage of the module. As pointed in #45192 the function usage should return fully initialized instance of the glob: https://git.io/Jf6WM /cc @Shinigami92 Thanks! Fixes #45192 --- types/glob/glob-tests.ts | 12 ++++++++++++ types/glob/index.d.ts | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/types/glob/glob-tests.ts b/types/glob/glob-tests.ts index 1db2335172..01f74acf8d 100644 --- a/types/glob/glob-tests.ts +++ b/types/glob/glob-tests.ts @@ -32,3 +32,15 @@ const Glob = glob.Glob; declare const ignore: ReadonlyArray; glob.sync('/foo/*', {realpath: true, realpathCache: {'/foo/bar': '/bar'}, ignore: '/foo/baz'}); glob.sync('/*', {ignore, nodir: true, cache: {'/': ['bar', 'baz']}, statCache: {'/foo/bar': false, '/foo/baz': {isDirectory() { return true; }}}}); + +// $ExpectType IGlob +const globInstance = glob('**/*.js', { mark: true }, (er, matches) => { + if (er) { + return; + } + er; // $ExpectType null + matches; // $ExpectType string[] +}); +globInstance.pause(); +globInstance.resume(); +globInstance.abort(); diff --git a/types/glob/index.d.ts b/types/glob/index.d.ts index fc8c98853d..a0bf99f19d 100644 --- a/types/glob/index.d.ts +++ b/types/glob/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: vvakame // voy // Klaus Meinhardt +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -10,8 +11,8 @@ import events = require("events"); import minimatch = require("minimatch"); -declare function G(pattern: string, cb: (err: Error | null, matches: string[]) => void): void; -declare function G(pattern: string, options: G.IOptions, cb: (err: Error | null, matches: string[]) => void): void; +declare function G(pattern: string, cb: (err: Error | null, matches: string[]) => void): G.IGlob; +declare function G(pattern: string, options: G.IOptions, cb: (err: Error | null, matches: string[]) => void): G.IGlob; declare namespace G { function __promisify__(pattern: string, options?: IOptions): Promise;