Skip to content

Commit 30ea58d

Browse files
committed
fix: improve add and unwatch TypeScript definitions
The return type of these methods should be `this` to support chaining.
1 parent 5c70fe3 commit 30ea58d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export class FSWatcher extends EventEmitter implements fs.FSWatcher {
1818
* Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
1919
* string.
2020
*/
21-
add(paths: string | ReadonlyArray<string>): void;
21+
add(paths: string | ReadonlyArray<string>): this;
2222

2323
/**
2424
* Stop watching files, directories, or glob patterns. Takes an array of strings or just one
2525
* string.
2626
*/
27-
unwatch(paths: string | ReadonlyArray<string>): void;
27+
unwatch(paths: string | ReadonlyArray<string>): this;
2828

2929
/**
3030
* Returns an object representing all the paths on the file system being watched by this

types/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const watcher = chokidar.watch("file, dir, or glob", {
99
const log = console.log.bind(console);
1010

1111
watcher
12+
.add('./foo.js')
13+
.unwatch('./bar.js')
1214
.on("add", (path: string) => {
1315
log("File", path, "has been added");
1416
})

0 commit comments

Comments
 (0)