[PR #5778] [MERGED] fix: string[] inference for additionalFields #6218

Closed
opened 2026-03-13 12:51:23 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5778
Author: @GautamBytes
Created: 11/5/2025
Status: Merged
Merged: 11/5/2025
Merged by: @Bekacru

Base: canaryHead: fix/string-array-inference


📝 Commits (2)

  • 29449d2 fix(types): correct string[] inference shadowing
  • 2f0d363 reverted change in test file

📊 Changes

1 file changed (+9 additions, -7 deletions)

View changed files

📝 packages/better-auth/src/db/field.ts (+9 -7)

📄 Description

Closes #5774

Description

This PR fixes a bug where additionalFields with type: 'string[]' were incorrectly inferred as number[] on the client. This caused TypeScript errors when using array methods like .includes().

The root cause was a variable shadowing bug in the InferValueType generic.

Changes

  1. packages/better-auth/src/db/field.ts:
    • Renamed the inner inferred type in InferValueType from T to U to resolve the shadowing.
    • Added a more precise Record<string, any> type for the json type.
  2. packages/better-auth/src/plugins/additional-fields/additional-fields.test.ts:
    • Added a new test case that specifically replicates the bug from #5774 (using input: false).
    • The test asserts that the inferred type is string[] and, more importantly, that the .includes() method correctly accepts a string parameter.

Summary by cubic

Fixes incorrect type inference for additionalFields with type "string[]" that returned number[] on the client, causing TypeScript errors (e.g., .includes). Updates InferValueType to correctly handle "string[]" and "json".

  • Bug Fixes
    • Prevented generic shadowing in InferValueType by renaming the inferred type (T → U) for ${infer U}[].
    • Correctly infers string[] for "string[]" and number[] for other arrays; adds Record<string, any> for "json".

Written for commit 2f0d36310d. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5778 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 11/5/2025 **Status:** ✅ Merged **Merged:** 11/5/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/string-array-inference` --- ### 📝 Commits (2) - [`29449d2`](https://github.com/better-auth/better-auth/commit/29449d24fc93b54b4b031d6c1aff0d0fdfc68f81) fix(types): correct string[] inference shadowing - [`2f0d363`](https://github.com/better-auth/better-auth/commit/2f0d36310d3cdbd23b911f591f79a56ee6cd32c0) reverted change in test file ### 📊 Changes **1 file changed** (+9 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/field.ts` (+9 -7) </details> ### 📄 Description Closes #5774 ## Description This PR fixes a bug where `additionalFields` with `type: 'string[]'` were incorrectly inferred as `number[]` on the client. This caused TypeScript errors when using array methods like `.includes()`. The root cause was a **variable shadowing** bug in the `InferValueType` generic. ## Changes 1. **`packages/better-auth/src/db/field.ts`**: * Renamed the inner inferred type in `InferValueType` from `T` to `U` to resolve the shadowing. * Added a more precise `Record<string, any>` type for the `json` type. 2. **`packages/better-auth/src/plugins/additional-fields/additional-fields.test.ts`**: * Added a new test case that specifically replicates the bug from #5774 (using `input: false`). * The test asserts that the inferred type is `string[]` and, more importantly, that the `.includes()` method correctly accepts a `string` parameter. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes incorrect type inference for additionalFields with type "string[]" that returned number[] on the client, causing TypeScript errors (e.g., .includes). Updates InferValueType to correctly handle "string[]" and "json". - **Bug Fixes** - Prevented generic shadowing in InferValueType by renaming the inferred type (T → U) for `${infer U}[]`. - Correctly infers string[] for "string[]" and number[] for other arrays; adds Record<string, any> for "json". <sup>Written for commit 2f0d36310d3cdbd23b911f591f79a56ee6cd32c0. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:51:23 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6218