[PR #5777] [CLOSED] Fix: string[] additionalFields inferred as number[] #6217

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5777
Author: @VishalDevx
Created: 11/5/2025
Status: Closed

Base: canaryHead: fix/additional-field-string-array


📝 Commits (1)

  • 5f4e208 Fix: string[] additionalFields inferred as number[]

📊 Changes

1 file changed (+21 additions, -15 deletions)

View changed files

📝 packages/better-auth/src/db/field.ts (+21 -15)

📄 Description

Summary

This PR fixes an issue where additional fields defined with the type string[]
were being incorrectly inferred as number[] during schema inference.

Root Cause

The type inference logic in InferValueType did not properly handle
string[] cases due to incorrect conditional type resolution.

Changes

  • Updated InferValueType in packages/better-auth/src/db/field.ts to correctly infer string[] fields.
  • Added support for distinguishing array types of string, number, boolean, and date.
  • Ensured type inference returns the correct array element type for all supported DB field types.

Impact

This resolves incorrect type mapping for array fields and prevents runtime type mismatches when dealing with additional schema fields.

Testing

  • Verified type inference manually for:
    • string[]
    • number[]
    • boolean[]
    • date[]
  • All types are now correctly resolved by TypeScript.

Summary by cubic

Fixes incorrect type inference where additionalFields declared as string[] were inferred as number[]. Array field types are now correctly resolved for string, number, boolean, and date.

  • Bug Fixes
    • Updated InferValueType in packages/better-auth/src/db/field.ts to correctly handle ${infer U}[].
    • Maps "string[]", "number[]", "boolean[]", and "date[]" to the right TypeScript types.
    • Prevents runtime type mismatches and incorrect schema typing for additional fields.

Written for commit 5f4e208306. 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/5777 **Author:** [@VishalDevx](https://github.com/VishalDevx) **Created:** 11/5/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/additional-field-string-array` --- ### 📝 Commits (1) - [`5f4e208`](https://github.com/better-auth/better-auth/commit/5f4e208306a90c1f90588c16a4f1174b56b797e2) Fix: string[] additionalFields inferred as number[] ### 📊 Changes **1 file changed** (+21 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/field.ts` (+21 -15) </details> ### 📄 Description ### Summary This PR fixes an issue where additional fields defined with the type `string[]` were being incorrectly inferred as `number[]` during schema inference. ### Root Cause The type inference logic in `InferValueType` did not properly handle `string[]` cases due to incorrect conditional type resolution. ### Changes - Updated `InferValueType` in `packages/better-auth/src/db/field.ts` to correctly infer `string[]` fields. - Added support for distinguishing array types of `string`, `number`, `boolean`, and `date`. - Ensured type inference returns the correct array element type for all supported DB field types. ### Impact This resolves incorrect type mapping for array fields and prevents runtime type mismatches when dealing with additional schema fields. ### Testing - Verified type inference manually for: - `string[]` - `number[]` - `boolean[]` - `date[]` - All types are now correctly resolved by TypeScript. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes incorrect type inference where additionalFields declared as string[] were inferred as number[]. Array field types are now correctly resolved for string, number, boolean, and date. - **Bug Fixes** - Updated InferValueType in packages/better-auth/src/db/field.ts to correctly handle `${infer U}[]`. - Maps "string[]", "number[]", "boolean[]", and "date[]" to the right TypeScript types. - Prevents runtime type mismatches and incorrect schema typing for additional fields. <sup>Written for commit 5f4e208306a90c1f90588c16a4f1174b56b797e2. 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:22 -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#6217