Skip to content

Commit 9470932

Browse files
authored
Merge pull request #1397 from paulmillr/unlink-types
fix: separate error emit args from regular emit args
2 parents 69c115a + 322e851 commit 9470932

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export type FSWInstanceOptions = BasicOpts & {
6060
};
6161

6262
export type ThrottleType = 'readdir' | 'watch' | 'add' | 'remove' | 'change';
63-
export type EmitArgs = [Path | Error, Stats?];
64-
export type EmitArgsWithName = [EventName, ...EmitArgs];
63+
export type EmitArgs = [path: Path, stats?: Stats];
64+
export type EmitErrorArgs = [error: Error, stats?: Stats];
65+
export type EmitArgsWithName = [event: EventName, ...EmitArgs];
6566
export type MatchFunction = (val: string, stats?: Stats) => boolean;
6667
export interface MatcherObject {
6768
path: string;
@@ -302,7 +303,7 @@ export interface FSWatcherKnownEventMap {
302303
[EV.READY]: [];
303304
[EV.RAW]: Parameters<WatchHandlers['rawEmitter']>;
304305
[EV.ERROR]: Parameters<WatchHandlers['errHandler']>;
305-
[EV.ALL]: [EventName, ...EmitArgs];
306+
[EV.ALL]: [event: EventName, ...EmitArgs];
306307
}
307308

308309
export type FSWatcherEventMap = FSWatcherKnownEventMap & {
@@ -602,7 +603,7 @@ export class FSWatcher extends EventEmitter<FSWatcherEventMap> {
602603
const opts = this.options;
603604
if (isWindows) path = sysPath.normalize(path);
604605
if (opts.cwd) path = sysPath.relative(opts.cwd, path);
605-
const args: EmitArgs = [path];
606+
const args: EmitArgs | EmitErrorArgs = [path];
606607
if (stats != null) args.push(stats);
607608

608609
const awf = opts.awaitWriteFinish;
@@ -637,7 +638,7 @@ export class FSWatcher extends EventEmitter<FSWatcherEventMap> {
637638
const awfEmit = (err?: Error, stats?: Stats) => {
638639
if (err) {
639640
event = EV.ERROR;
640-
args[0] = err;
641+
(args as unknown as EmitErrorArgs)[0] = err;
641642
this.emitWithAll(event, args);
642643
} else if (stats) {
643644
// if stats doesn't exist the file must have been deleted

0 commit comments

Comments
 (0)