Skip to content

Commit c75c8d5

Browse files
committed
fix(fs): return Generator from walkSync and expandGlobSync
walkSync and expandGlobSync are generator functions, so at runtime they already have iterator helpers (map, filter, take, drop, toArray, ...). Their declared return type IterableIterator<WalkEntry> hides those helpers from TypeScript, forcing callers to wrap with Array.from() or write a manual loop just to use them. Narrow the return type to Generator<WalkEntry>. Generator extends IterableIterator so existing callers stay assignment-compatible, but the helpers become visible: walkSync(".").map((e) => e.name).toArray() // now type-checks Async versions (walk, expandGlob) keep AsyncIterableIterator because the async iterator helpers aren't in the TypeScript lib that Deno currently ships, so claiming them would mislead callers. Fixes #7099
1 parent cdf74a8 commit c75c8d5

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

fs/expand_glob.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export async function* expandGlob(
428428
export function* expandGlobSync(
429429
glob: string | URL,
430430
options?: ExpandGlobOptions,
431-
): IterableIterator<WalkEntry> {
431+
): Generator<WalkEntry> {
432432
let {
433433
root,
434434
exclude = [],
@@ -473,7 +473,7 @@ export function* expandGlobSync(
473473
function* advanceMatch(
474474
walkInfo: WalkEntry,
475475
globSegment: string,
476-
): IterableIterator<WalkEntry> {
476+
): Generator<WalkEntry> {
477477
if (!walkInfo.isDirectory) {
478478
return;
479479
} else if (globSegment === "..") {

fs/walk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ export async function* walk(
878878
export function* walkSync(
879879
root: string | URL,
880880
options?: WalkOptions,
881-
): IterableIterator<WalkEntry> {
881+
): Generator<WalkEntry> {
882882
let {
883883
maxDepth = Infinity,
884884
includeFiles = true,

0 commit comments

Comments
 (0)