mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
63 lines
1.2 KiB
TypeScript
63 lines
1.2 KiB
TypeScript
import * as walk from "walk";
|
|
|
|
const options: walk.WalkOptions = {
|
|
followLinks: true,
|
|
filters: ['.gitignore'],
|
|
listeners: {
|
|
directories: () => { },
|
|
directory: () => { },
|
|
directoryError: () => { },
|
|
end: () => { },
|
|
errors: () => { },
|
|
file: () => { },
|
|
files: () => { },
|
|
names: () => { },
|
|
nodeError: () => { }
|
|
}
|
|
};
|
|
|
|
// $ExpectType Walker
|
|
const walker = walk.walk('.', options);
|
|
walker.on('directories', (
|
|
// $ExpectType string
|
|
root,
|
|
// $ExpectType WalkStats[]
|
|
statsArray,
|
|
// $ExpectType WalkNext
|
|
next
|
|
) => {
|
|
root.trim();
|
|
statsArray.forEach((stats) => `${stats.name} (${stats.type})`);
|
|
next();
|
|
});
|
|
|
|
walker.on('file', (
|
|
// $ExpectType string
|
|
root,
|
|
// $ExpectType WalkStats
|
|
stats,
|
|
// $ExpectType WalkNext
|
|
next
|
|
) => {
|
|
// $ExpectError
|
|
if (stats.type === 'foo') {
|
|
//
|
|
}
|
|
|
|
switch (stats.type) {
|
|
case "blockDevice":
|
|
case "characterDevice":
|
|
case "directory":
|
|
case "FIFO":
|
|
case "file":
|
|
case "socket":
|
|
case "symbolicLink":
|
|
// All good
|
|
break;
|
|
}
|
|
});
|
|
// $ExpectError
|
|
walker.on('foo', () => { });
|
|
walker.pause();
|
|
walker.resume();
|