fix(client): use direct imports to fix bundler re-export type resolution#8261
fix(client): use direct imports to fix bundler re-export type resolution#8261
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
@better-auth/api-key
better-auth
auth
@better-auth/core
@better-auth/drizzle-adapter
@better-auth/electron
@better-auth/expo
@better-auth/i18n
@better-auth/kysely-adapter
@better-auth/memory-adapter
@better-auth/mongo-adapter
@better-auth/oauth-provider
@better-auth/passkey
@better-auth/prisma-adapter
@better-auth/redis-storage
@better-auth/scim
@better-auth/sso
@better-auth/stripe
@better-auth/telemetry
@better-auth/test-utils
commit: |
There was a problem hiding this comment.
Pull request overview
This PR fixes broken client typings (notably updateUser and updateSession) by refining how request context types are inferred for client endpoints, avoiding cases where InputContext inference collapses to any.
Changes:
- Introduces metadata-based body inference (
metadata.$Infer.body) for endpoint call signatures to preventanyleakage. - Adds
InferEndpointCtxto choose between metadata-inferred body types and the existingInferCtxfallback. - Ensures
/update-userkeeps a dedicated, client-options-based input type (InferUserUpdateCtx) regardless of required/optional-arg detection.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -138,25 +149,26 @@ export type InferRoute<API, COpts extends BetterAuthClientOptions> = | |||
| C["params"] | |||
| >, | |||
| >( | |||
| ...data: HasRequiredKeys< | |||
| InferCtx<C, FetchOptions> | |||
| > extends true | |||
| ...data: T["path"] extends `/update-user` | |||
| ? [ | |||
| Prettify< | |||
| T["path"] extends `/sign-up/email` | |||
| ? InferSignUpEmailCtx<COpts, FetchOptions> | |||
| : InferCtx<C, FetchOptions> | |||
| >, | |||
| FetchOptions?, | |||
| ] | |||
| : [ | |||
| Prettify< | |||
| T["path"] extends `/update-user` | |||
| ? InferUserUpdateCtx<COpts, FetchOptions> | |||
| : InferCtx<C, FetchOptions> | |||
| >?, | |||
| Prettify<InferUserUpdateCtx<COpts, FetchOptions>>?, | |||
| FetchOptions?, | |||
| ] | |||
| : HasRequiredKeys< | |||
| InferEndpointCtx<T, C, FetchOptions> | |||
| > extends true | |||
| ? [ | |||
| Prettify< | |||
| T["path"] extends `/sign-up/email` | |||
| ? InferSignUpEmailCtx<COpts, FetchOptions> | |||
| : InferEndpointCtx<T, C, FetchOptions> | |||
| >, | |||
| FetchOptions?, | |||
| ] | |||
| : [ | |||
| Prettify<InferEndpointCtx<T, C, FetchOptions>>?, | |||
| FetchOptions?, | |||
There was a problem hiding this comment.
The new endpoint-context inference now depends on metadata.$Infer.body (via InferEndpointCtx) to avoid any leaking from InputContext. There are existing type-level tests in packages/better-auth/src/client/client.test.ts, but none that assert the updateUser / updateSession call signatures; adding a couple expectTypeOf(client.updateUser) / expectTypeOf(client.updateSession) assertions would help prevent regressions of issue #8258.
6166531 to
e3dceb4
Compare
The bundler (tsdown/rolldown) doesn't include re-exported types from external packages in `declare namespace` blocks. Importing through local barrel re-exports (e.g., `../db`, `../..`) caused types like `InferDBFieldsFromPluginsInput` and `GenericEndpointContext` to be unresolvable in the build output, collapsing to `any`. - Revert path-to-object.ts workarounds (no longer needed) - Fix jwt/types.ts: import GenericEndpointContext from @better-auth/core
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/better-auth/src/client/path-to-object.ts">
<violation number="1" location="packages/better-auth/src/client/path-to-object.ts:103">
P1: The new `IsAny<C["body"]>` branch omits the optional-query case, so endpoints with `body: any` and `query: Record | undefined` lose their `query` input type.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| } | ||
| : C["query"] extends Record<string, any> | ||
| IsAny<C["body"]> extends true | ||
| ? C["query"] extends Record<string, any> |
There was a problem hiding this comment.
P1: The new IsAny<C["body"]> branch omits the optional-query case, so endpoints with body: any and query: Record | undefined lose their query input type.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/better-auth/src/client/path-to-object.ts, line 103:
<comment>The new `IsAny<C["body"]>` branch omits the optional-query case, so endpoints with `body: any` and `query: Record | undefined` lose their `query` input type.</comment>
<file context>
@@ -89,35 +89,61 @@ export type InferUserUpdateCtx<
- }
- : C["query"] extends Record<string, any>
+ IsAny<C["body"]> extends true
+ ? C["query"] extends Record<string, any>
? {
query: C["query"];
</file context>
Fixes: #8258