Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine types: arrays may be readonly #877

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export class FSWatcher extends EventEmitter implements fs.FSWatcher {
* Add files, directories, or glob patterns for tracking. Takes an array of strings or just one
* string.
*/
add(paths: string | string[]): void;
add(paths: string | ReadonlyArray<string>): void;

/**
* Stop watching files, directories, or glob patterns. Takes an array of strings or just one
* string.
*/
unwatch(paths: string | string[]): void;
unwatch(paths: string | ReadonlyArray<string>): void;

/**
* Returns an object representing all the paths on the file system being watched by this
Expand Down Expand Up @@ -182,6 +182,6 @@ export interface AwaitWriteFinishOptions {
* produces an instance of `FSWatcher`.
*/
export function watch(
paths: string | string[],
paths: string | ReadonlyArray<string>,
options?: WatchOptions
): FSWatcher;
6 changes: 6 additions & 0 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ chokidar
.on("all", (event: string, path: string) => {
console.log(event, path);
});

// watch an (readonly-) array of files
const files: ReadonlyArray<string> = ["a", "b"];
const watcher2 = chokidar.watch(files);
watcher2.add(["c", "d"] as ReadonlyArray<string>);
watcher2.unwatch(["b"] as ReadonlyArray<string>);