Skip to content

Commit

Permalink
Refine types: arrays may be readonly (#878).
Browse files Browse the repository at this point in the history
  • Loading branch information
elmarx authored and paulmillr committed Aug 21, 2019
1 parent a8f250e commit 775420f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions types/index.d.ts
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;
15 changes: 15 additions & 0 deletions types/test.ts
Expand Up @@ -58,3 +58,18 @@ chokidar
.on("all", (event: string, path: string) => {
console.log(event, path);
});

// test readonly arrays
const listOfFiles = ["a", "b"];
const readonlyFiles: ReadonlyArray<string> = listOfFiles;

const readonlyInputWatcher = chokidar.watch(readonlyFiles);
const mutableInputWatcher = chokidar.watch(listOfFiles);

const anotherListOfFiles = ["c", "d"];
const anotherReadonlyList: ReadonlyArray<string> = anotherListOfFiles;

readonlyInputWatcher.add(anotherReadonlyList);
mutableInputWatcher.add(anotherListOfFiles);

readonlyInputWatcher.unwatch(["b"] as ReadonlyArray<string>);

0 comments on commit 775420f

Please sign in to comment.