fix: restrict route guard property to function type only#26
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 43 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughA patch version bump (0.12.1 → 0.12.2) introducing type safety improvements for route guards. The Routes interface now explicitly declares an optional Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@CHANGELOG.md`:
- Around line 8-10: Add a new changelog section for version 0.12.2 between the
existing [Unreleased] and [0.12.1] headings documenting the type-safety fix for
the "?" guard key (issue `#10`); include a concise entry under "## [0.12.2] -
2026-04-01" (or the correct release date) that mentions the fix to the "?" guard
key type safety and references issue `#10`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 673ab576-48a9-44d8-8972-184a4da2f648
📒 Files selected for processing (6)
CHANGELOG.mdpackages/esroute-lit/package.jsonpackages/esroute/package.jsonpackages/esroute/src/route-resolver.spec.tspackages/esroute/src/route-resolver.tspackages/esroute/src/routes.ts
| ## [Unreleased] | ||
|
|
||
| ## [0.12.1] - 2026-04-01 |
There was a problem hiding this comment.
Missing changelog entry for version 0.12.2.
The package version is bumped to 0.12.2, but there's no corresponding changelog entry documenting the type safety fix for the "?" guard key (issue #10). Add a section between [Unreleased] and [0.12.1]:
📝 Suggested changelog entry
## [Unreleased]
+## [0.12.2] - 2026-04-XX
+
+### Fixed
+- Route guard property `"?"` is now restricted to function type only, preventing accidental assignment of sub-routes objects (closes `#10`)
+
## [0.12.1] - 2026-04-01📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## [Unreleased] | |
| ## [0.12.1] - 2026-04-01 | |
| ## [Unreleased] | |
| ## [0.12.2] - 2026-04-XX | |
| ### Fixed | |
| - Route guard property `"?"` is now restricted to function type only, preventing accidental assignment of sub-routes objects (closes `#10`) | |
| ## [0.12.1] - 2026-04-01 |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@CHANGELOG.md` around lines 8 - 10, Add a new changelog section for version
0.12.2 between the existing [Unreleased] and [0.12.1] headings documenting the
type-safety fix for the "?" guard key (issue `#10`); include a concise entry under
"## [0.12.2] - 2026-04-01" (or the correct release date) that mentions the fix
to the "?" guard key type safety and references issue `#10`.
✅ Addressed in commit 60c5346
|
Done — added the 0.12.2 changelog entry. |
The `"?"` key in `Routes` now only accepts `Resolve<T, S>` (a guard function), not a sub-routes object. Adds a type test to verify the constraint, and bumps versions to 0.12.2. Closes #10
60c5346 to
2a5f7d6
Compare
Summary
"?"?: Resolve<T, S>as an explicit named property to theRoutesinterface, restricting the guard key to functions only (previously the index signature allowed anyRoutes | Resolvevalue)route-resolver.tsinternal variable types to handleundefinednow returned by the widened index signature"?"is a TypeScript errorCloses #10
Test plan
npm run typecheckpassesnpm testpasses (60 tests){ "?": { foo: () => "foo" } }toRoutesis a TS error (@ts-expect-errorconfirmed){ "?": () => undefined }toRoutesis validSummary by CodeRabbit
Documentation
Improvements
Chores