fix(fs): return Generator from walkSync and expandGlobSync so iterator helpers are visible#7166
Open
LeSingh1 wants to merge 2 commits into
Open
fix(fs): return Generator from walkSync and expandGlobSync so iterator helpers are visible#7166LeSingh1 wants to merge 2 commits into
LeSingh1 wants to merge 2 commits into
Conversation
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 denoland#7099
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7166 +/- ##
=======================================
Coverage 94.57% 94.57%
=======================================
Files 636 636
Lines 52142 52142
Branches 9401 9401
=======================================
Hits 49315 49315
Misses 2249 2249
Partials 578 578 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Deno v1.x's TypeScript lib infers Generator<T>'s default TNext as unknown, which conflicts with the inner walkSync's yield* delegation expecting undefined (TS2766). Pin TReturn=void and TNext=undefined to match what the generators actually produce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7099.
walkSyncandexpandGlobSyncare generator functions, so at runtime they already have iterator helpers (map,filter,take,drop,toArray, ...). Their declared return typeIterableIterator<WalkEntry>hides those helpers from TypeScript and forces callers to wrap withArray.from(...)or write a manual loop just to use them.From the issue:
Narrowing the return type to
Generator<WalkEntry>exposes the helpers.GeneratorextendsIterableIteratorso existing callers stay assignment-compatible:The async siblings (
walk,expandGlob) are intentionally left asAsyncIterableIterator<WalkEntry>. The async iterator helpers aren't in the TypeScript lib that Deno currently ships, so claiming them on the return type would mislead callers into writing code that breaks at type-check time. Happy to change this if the right lib is on by default and I missed it.Verification: ran
fs/walk_test.ts+fs/expand_glob_test.tswith-A, 63 pass / 4 fail — the 4 failures (accepts skip option as regExps×2,walks fifo files on unix×2) reproduce on cleanorigin/mainso they're pre-existing and unrelated.