Enabling noUncheckedIndexedAccess#3426
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughEnables TypeScript noUncheckedIndexedAccess and applies non-null assertions and safer iteration across source and tests; tightens SSE handling by asserting event schemas and throwing ResultHandlerError when an empty events map is provided; updates CHANGELOG with v28.1.1. ChangesTypeScript Strictness Enablement
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels:
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (2)
express-zod-api/tests/sse.spec.ts (1)
157-159: ⚡ Quick winAssert the thrown error type, not only snapshot text.
This test currently allows any thrown error with matching snapshot. Please assert
ResultHandlerErrorexplicitly to lock the
contract.Proposed change
+import { ResultHandlerError } from "../src/errors"; @@ - test("should throw when events map is empty", () => { - expect(() => makeResultHandler({})).toThrowErrorMatchingSnapshot(); - }); + test("should throw when events map is empty", () => { + expect(() => makeResultHandler({})).toThrowError(ResultHandlerError); + expect(() => makeResultHandler({})).toThrowErrorMatchingSnapshot(); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@express-zod-api/tests/sse.spec.ts` around lines 157 - 159, The test "should throw when events map is empty" must assert the specific error type: update the test invoking makeResultHandler({}) to expect a thrown ResultHandlerError (use toThrow or toThrowError with the ResultHandlerError constructor or instanceof check) in addition to or instead of toThrowErrorMatchingSnapshot; import or reference ResultHandlerError from the module where it's defined and ensure the assertion verifies the error is an instance of ResultHandlerError while preserving the snapshot assertion if desired.express-zod-api/src/sse.ts (1)
13-13: ⚡ Quick win
.tsextension in local imports is allowed in this repo, so it’s not a build-breaking issue.
express-zod-api/src/sse.ts:13imports./errors.ts; the roottsconfig.jsonsetscompilerOptions.allowImportingTsExtensions: true, andexpress-zod-api/tsconfig.jsonextends it—so module resolution/build settings shouldn’t be affected. Keeping (or removing) the.tssuffix is a consistency/style choice only.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@express-zod-api/src/sse.ts` at line 13, The import in express-zod-api/src/sse.ts currently uses a .ts extension ("./errors.ts"); align it with the repository's import style by removing the extension so the import reads "./errors" instead, updating the existing import of ResultHandlerError in sse.ts to match other local imports and maintain consistency across the codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@express-zod-api/src/sse.ts`:
- Line 13: The import in express-zod-api/src/sse.ts currently uses a .ts
extension ("./errors.ts"); align it with the repository's import style by
removing the extension so the import reads "./errors" instead, updating the
existing import of ResultHandlerError in sse.ts to match other local imports and
maintain consistency across the codebase.
In `@express-zod-api/tests/sse.spec.ts`:
- Around line 157-159: The test "should throw when events map is empty" must
assert the specific error type: update the test invoking makeResultHandler({})
to expect a thrown ResultHandlerError (use toThrow or toThrowError with the
ResultHandlerError constructor or instanceof check) in addition to or instead of
toThrowErrorMatchingSnapshot; import or reference ResultHandlerError from the
module where it's defined and ensure the assertion verifies the error is an
instance of ResultHandlerError while preserving the snapshot assertion if
desired.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 82da7673-bb4a-4268-9ef9-b144d6a76744
⛔ Files ignored due to path filters (1)
express-zod-api/tests/__snapshots__/sse.spec.ts.snapis excluded by!**/*.snap
📒 Files selected for processing (19)
CHANGELOG.mdexpress-zod-api/src/diagnostics.tsexpress-zod-api/src/documentation-helpers.tsexpress-zod-api/src/json-schema-helpers.tsexpress-zod-api/src/routing-walker.tsexpress-zod-api/src/sse.tsexpress-zod-api/src/typescript-api.tsexpress-zod-api/src/zts.tsexpress-zod-api/tests/cookie-middleware.spec.tsexpress-zod-api/tests/endpoints-factory.spec.tsexpress-zod-api/tests/result-handler.spec.tsexpress-zod-api/tests/routing.spec.tsexpress-zod-api/tests/server-helpers.spec.tsexpress-zod-api/tests/server.spec.tsexpress-zod-api/tests/sse.spec.tsexpress-zod-api/tests/system.spec.tsmigration/index.spec.tsmigration/index.tstsconfig.json
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — enabling noUncheckedIndexedAccess in the root tsconfig.json and adjusting source, test, and migration code to compile under the stricter checks, plus adding a runtime guard in makeResultHandler for empty EventsMap.
- Enable
noUncheckedIndexedAccessin roottsconfig.json. - Refactor index-based loops to
for...ofwhere the index was only used for array access (diagnostics.ts,json-schema-helpers.ts). - Add justified non-null assertions (
!) with inline comments where runtime invariants guarantee safety (routing-walker.ts,sse.ts,typescript-api.ts,zts.ts, tests). - Throw
ResultHandlerErrorinmakeResultHandlerwhen the events map is empty, preventing an invalid schema at runtime. - Add runtime length assertions in tests before indexed access (
endpoints-factory.spec.ts). - Add
assertguard inmigration/index.spec.tsfor rule lookup.
ℹ️ tools/ files not adjusted for the new flag
The root tsconfig.json has no exclude array, so tools/headers.ts, tools/make-tests.ts, and tools/rfc-agent.ts are included in root-level type-checking. These files currently emit noUncheckedIndexedAccess errors. They appear to be auxiliary scripts rather than production code, and CI likely runs tsc per-workspace, so this is a minor coverage gap rather than a blocking issue.
Kimi K2 | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the makeResultHandler empty-events guard was moved from eager (at factory call time) to lazy (inside the positive callback), aligning the throw timing with how ResultHandler evaluates its positive schema. Tests and snapshots were updated accordingly.
- Refactored
makeResultHandlerinexpress-zod-api/src/sse.tsto throwResultHandlerErrorlazily within thepositivecallback instead of at factory invocation time. - Updated
sse.spec.tsto assert the throw viarh.getPositiveResponse()rather than atmakeResultHandler()construction time. - Updated snapshot to match the renamed test case.
- Simplified
EventStreamFactoryinheritance test to use an empty events map.
Kimi K2 | 𝕏

Summary by CodeRabbit
Bug Fixes
Chores
Documentation
Tests