feat(types)!: remove TypeBox schema type inference#54
Conversation
BREAKING CHANGE: Automatic type inference from TypeBox schemas has been removed. Runtime schema validation remains supported.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe ChangesTypeBox Schema Type Inference
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
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 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/client.test.ts (1)
565-569: ⚡ Quick winUse a single
@ts-expect-erroron the call expression, not per object property.Property-level directives here are brittle to TypeScript diagnostic-location changes and can produce noisy “unused
@ts-expect-error” failures. Prefer one directive on theclient.delete(...)call.Suggested change
- const deletedItem = await client.delete("/items/:itemId", { - // `@ts-expect-error` invalid typebox support. - params: { itemId: "123" }, - // `@ts-expect-error` invalid typebox support. - searchParams: { force: "true" }, - }) + // `@ts-expect-error` invalid typebox support. + const deletedItem = await client.delete("/items/:itemId", { + params: { itemId: "123" }, + searchParams: { force: "true" }, + })🤖 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 `@test/client.test.ts` around lines 565 - 569, The test uses multiple property-level `@ts-expect-error` comments on the params and searchParams objects which is brittle; instead place a single `@ts-expect-error` on the client.delete(...) call expression. Update the test so the invalid TypeBox types remain suppressed by one directive applied to the call to client.delete (referencing the client.delete(...) invocation and the params/searchParams objects) rather than per-property comments.
🤖 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.
Inline comments:
In `@src/`@types/client.ts:
- Around line 12-13: InferSchema currently maps Kind extends "typebox" to T (the
TypeBox schema type) which causes InferContent to treat schema metadata as the
runtime payload; change the TypeBox branch to return unknown instead of T so
TypeBox schemas don't lock the client API to the schema type. Update the
conditional in InferSchema (the branch checking Kind extends "typebox") to use
unknown, and ensure any downstream usage in InferContent that composes
params/searchParams/body (the types that consume InferSchema) still expects the
runtime shape (now unknown) rather than T.
---
Nitpick comments:
In `@test/client.test.ts`:
- Around line 565-569: The test uses multiple property-level `@ts-expect-error`
comments on the params and searchParams objects which is brittle; instead place
a single `@ts-expect-error` on the client.delete(...) call expression. Update the
test so the invalid TypeBox types remain suppressed by one directive applied to
the call to client.delete (referencing the client.delete(...) invocation and the
params/searchParams objects) rather than per-property comments.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7791114a-cf3c-4a50-aafe-eb936a69d37f
📒 Files selected for processing (2)
src/@types/client.tstest/client.test.ts
Description
This pull request removes TypeBox-based type inference for the
searchParams,params, andbodyfields from the client functions returned bycreateClient.Previously, these types were inferred using TypeBox's
Statictype. However,Staticintroduces a significant amount of type-level computation and has proven to be extremely expensive for TypeScript performance. To reduce the number of type instantiations and improve compile-time performance, this PR removes the use ofStaticfrom the client implementation while preserving runtime schema validation.The client type system still infers whether
searchParams,params, orbodyare required for a given endpoint. However, it no longer infers the individual fields within those objects.In #52, TypeBox-based inference for
searchParams,params, andbodywas removed from middleware and handler contexts based on the diagnostics performed in that pull request. However, during the investigation in aura-stack-ts/auth#179, it was discovered thatclient.tswas still responsible for a large number of expensive type operations due to the remaining usage of TypeBox'sStatictype.Diagnostic Results
The following results show the number of TypeScript instantiations after the changes introduced by this PR:
srconlysrcandbenchsrc,bench, andtestUsage
Related PRs