Skip to content

Commit

Permalink
feat: infer type of the output values
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Jun 9, 2019
1 parent a505273 commit 09f0107
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import Provider from './providers/provider';
import ProviderStream from './providers/stream';
import ProviderSync from './providers/sync';
import Settings, { Options } from './settings';
import { EntryItem, Pattern } from './types/index';
import { Entry, EntryItem, Pattern } from './types/index';
import * as utils from './utils/index';

type Task = taskManager.Task;

type EntryObjectModePredicate = { [P in keyof Pick<Options, 'objectMode'>]-?: true };
type EntryStatsPredicate = { [P in keyof Pick<Options, 'stats'>]-?: true };
type EntryObjectPredicate = EntryObjectModePredicate | EntryStatsPredicate;

function sync(source: Pattern | Pattern[], options: Options & EntryObjectPredicate): Entry[];
function sync(source: Pattern | Pattern[], options?: Options): string[];
function sync(source: Pattern | Pattern[], options?: Options): EntryItem[] {
assertPatternsInput(source);

Expand All @@ -17,6 +23,8 @@ function sync(source: Pattern | Pattern[], options?: Options): EntryItem[] {
return utils.array.flatten(works);
}

function async(source: Pattern | Pattern[], options: Options & EntryObjectPredicate): Promise<Entry[]>;
function async(source: Pattern | Pattern[], options?: Options): Promise<string[]>;
function async(source: Pattern | Pattern[], options?: Options): Promise<EntryItem[]> {
try {
assertPatternsInput(source);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/smoke/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ function getFastGlobEntries(pattern: Pattern, ignore?: Pattern, cwd?: string, op
...opts
};

return fg.sync(pattern, options).sort() as string[];
return fg.sync(pattern, options).sort();
}

0 comments on commit 09f0107

Please sign in to comment.