fix(server): type rules.entitlement() with registered Entitlement union [#2992]#2993
Merged
viniciusdacal merged 2 commits intomainfrom Apr 24, 2026
Merged
fix(server): type rules.entitlement() with registered Entitlement union [#2992]#2993viniciusdacal merged 2 commits intomainfrom
viniciusdacal merged 2 commits intomainfrom
Conversation
…on [#2992] Closes #2992. rules.entitlement() took a raw string, so typos like 'task:udpate' passed both TypeScript and the compiler and only failed at runtime. The codegen path that augments EntitlementRegistry already existed; the builder just wasn't consuming it. Switch the parameter to the Entitlement type so the narrowing propagates end-to-end: typos become TS errors and autocomplete surfaces declared entitlements. Falls back to string when the registry is empty so projects that haven't run codegen keep compiling. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ows rules.entitlement end-to-end [#2992] Simulates what @vertz/codegen's AccessTypesGenerator emits into access.d.ts and confirms the narrowing actually propagates through the published @vertz/server boundary: declared entitlements compile, typos trip ts-expect-error, and the same narrowing reaches AccessContext.can/authorize. Without this test the previous fix only proved the signature references Entitlement, not that codegen's output is wired through correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Closes #2992.
rules.entitlement(name)accepted anystring, so typos likerules.entitlement('task:udpate')compiled cleanly and only surfaced at runtime. Narrows the parameter to theEntitlementtype so typos become TypeScript errors and autocomplete surfaces declared entitlements.@vertz/codegen'sAccessTypesGeneratoralready emitsdeclare module '@vertz/server' { interface EntitlementRegistry { ... } }intoaccess.d.ts, andEntitlement = keyof EntitlementRegistry extends never ? string : Extract<keyof EntitlementRegistry, string>is defined inaccess-context.ts. The builder just wasn't consuming theEntitlementtype.stringwhen the registry is empty, so projects that haven't run codegen keep compiling.Public API Changes
packages/server/src/auth/rules.ts—rules.entitlement(name: string)→rules.entitlement(name: Entitlement). Non-breaking whenEntitlementRegistryis empty (parameter resolves tostring); narrows in projects where codegen has emittedaccess.d.ts.Test plan
tsgo --noEmitclean on@vertz/server(bothtsconfig.jsonandtsconfig.typecheck.json)oxlintclean on changed filesvtz test— 2193 passed, 0 failed on@vertz/server, including the newrules.test-d.ts.test-d.tscovers positive (accepts string fallback) and negative (@ts-expect-erroron non-string inputs) cases🤖 Generated with Claude Code