Skip to content

fix: restrict route guard property to function type only#26

Merged
sv2dev merged 2 commits intomainfrom
fix/guard-type-restriction
Mar 31, 2026
Merged

fix: restrict route guard property to function type only#26
sv2dev merged 2 commits intomainfrom
fix/guard-type-restriction

Conversation

@sv2dev
Copy link
Copy Markdown
Owner

@sv2dev sv2dev commented Mar 31, 2026

Summary

  • Adds "?"?: Resolve<T, S> as an explicit named property to the Routes interface, restricting the guard key to functions only (previously the index signature allowed any Routes | Resolve value)
  • Updates route-resolver.ts internal variable types to handle undefined now returned by the widened index signature
  • Adds a type test verifying that assigning a sub-routes object to "?" is a TypeScript error

Closes #10

Test plan

  • npm run typecheck passes
  • npm test passes (60 tests)
  • Assigning { "?": { foo: () => "foo" } } to Routes is a TS error (@ts-expect-error confirmed)
  • Assigning { "?": () => undefined } to Routes is valid

Summary by CodeRabbit

  • Documentation

    • Added comprehensive project changelog documenting release history and features.
  • Improvements

    • Enhanced route resolution handling for edge cases.
  • Chores

    • Version bumped to 0.12.2 across packages.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Warning

Rate limit exceeded

@sv2dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 43 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 89cfd792-f53a-4ef7-91f2-f239c56324c9

📥 Commits

Reviewing files that changed from the base of the PR and between 2b89824 and 2a5f7d6.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • packages/esroute-lit/package.json
  • packages/esroute/package.json
  • packages/esroute/src/route-resolver.spec.ts
  • packages/esroute/src/route-resolver.ts
  • packages/esroute/src/routes.ts

Walkthrough

A patch version bump (0.12.1 → 0.12.2) introducing type safety improvements for route guards. The Routes interface now explicitly declares an optional "?" property restricted to Resolve functions, preventing route objects from being assigned to the guard key. Runtime checks in route-resolver validate guard handling with undefined routes.

Changes

Cohort / File(s) Summary
Documentation & Versioning
CHANGELOG.md, packages/esroute/package.json, packages/esroute-lit/package.json
Added changelog documenting project history from v0.1.0 to unreleased; bumped package versions from 0.12.1 to 0.12.2.
Route Type System
packages/esroute/src/routes.ts
Modified Routes<T, S> interface: added optional "?"?: Resolve<T, S> property to explicitly restrict guard key to functions; updated catch-all index signature to permit undefined values alongside routes and resolves.
Route Resolver Logic & Tests
packages/esroute/src/route-resolver.ts, packages/esroute/src/route-resolver.spec.ts
Enhanced getResolves to treat routes as potentially undefined in addition to null; added explicit null check before guard evaluation. Added TypeScript type assertion test verifying that assigning a route object to the "?" guard key fails compilation while functions are permitted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #25: Modifies packages/esroute/src/route-resolver.ts with adjustments to navPath typing and initialization that interact with the guard-handling changes here.
  • PR #23: Updates both routes.ts and route-resolver.ts to implement broader type/generic plumbing for routes and navigation state, directly complementing the route guard type refinements in this PR.

Poem

🐰 A guard that was wild, now tame and refined,
With "?" strict-typed, no objects allowed,
The Routes interface knows what's assigned,
Type safety hops forward, oh how we're proud!
undefined and null both handled right,
Route resolution shines in the morning light! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: restricting the route guard property ('?') to function type only, which aligns with the primary objective of the pull request.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #10 [#10]: added explicit '?' property to Routes interface, updated resolver types to handle undefined, and included TypeScript type tests.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the type restriction for the '?' guard property. The CHANGELOG and version bumps are appropriate accompanying changes for a released version.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/guard-type-restriction

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e3b6069 and 2b89824.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • packages/esroute-lit/package.json
  • packages/esroute/package.json
  • packages/esroute/src/route-resolver.spec.ts
  • packages/esroute/src/route-resolver.ts
  • packages/esroute/src/routes.ts

Comment on lines +8 to +10
## [Unreleased]

## [0.12.1] - 2026-04-01
Copy link
Copy Markdown

@coderabbitai coderabbitai bot Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
## [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

@sv2dev
Copy link
Copy Markdown
Owner Author

sv2dev commented Mar 31, 2026

Done — added the 0.12.2 changelog entry.

Sven Rogge added 2 commits April 1, 2026 01:41
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
@sv2dev sv2dev force-pushed the fix/guard-type-restriction branch from 60c5346 to 2a5f7d6 Compare March 31, 2026 23:41
@sv2dev sv2dev merged commit 8c3d8e6 into main Mar 31, 2026
2 checks passed
@sv2dev sv2dev deleted the fix/guard-type-restriction branch March 31, 2026 23:42
@coderabbitai coderabbitai bot mentioned this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Route guard properties should not only allow a guard function

1 participant