[GH-ISSUE #5268] Misleading typing on inferAdditionalFields #18830

Closed
opened 2026-04-15 17:30:48 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ofek-frame on GitHub (Oct 13, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5268

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Might be misleading only to me, but:

Create an additional field with a literal array type - Which matches the TS definition:

type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;

Later on it will be turned into a string array - not enums, as one may infer from the type
00706f30fb/packages/cli/src/generators/drizzle.ts (L72-L78)

Current vs. Expected behavior

Currently, the auth-schema would include a string array in that case.
I'd expect it to generate an enum (Or a string with a validator, if the backing store doesn't support enums).

What version of Better Auth are you using?

canary

System info

Irrelevant

Which area(s) are affected? (Select all that apply)

Types

Auth config (if applicable)

    inferAdditionalFields({
      user: {
        idToken: {
          type: ['string', 'test'],
        },
       }
     })

Additional context

No response

Originally created by @ofek-frame on GitHub (Oct 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5268 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Might be misleading only to me, but: Create an additional field with a literal array type - Which matches the TS definition: ```ts type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>; ``` Later on it will be turned into a string array - not enums, as one may infer from the type https://github.com/better-auth/better-auth/blob/00706f30fb21c72aa1d75acd7d3efdb5c00497c4/packages/cli/src/generators/drizzle.ts#L72-L78 ### Current vs. Expected behavior Currently, the auth-schema would include a string array in that case. I'd expect it to generate an enum (Or a string with a validator, if the backing store doesn't support enums). ### What version of Better Auth are you using? canary ### System info ```bash Irrelevant ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript inferAdditionalFields({ user: { idToken: { type: ['string', 'test'], }, } }) ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 17:30:48 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 13, 2025):

Hi @ofek-frame! I'm Dosu and I’m helping the better-auth team.

You're right—the current implementation maps TypeScript literal array types like ${"string" | "number"}[] to plain string arrays in the generated schema, without enforcing enum-like constraints or validation. This can be misleading, since the type signature suggests stricter validation than what actually happens at the schema level. There isn't special handling for enum arrays or validated string arrays in the schema generation logic; everything gets converted to a string array regardless of the literal type definition see drizzle.ts implementation.

If you need enum-like validation, you'll need to add custom validation logic at the application level for now. This is a gap between the type system and the generated schema, and clarifying this in the documentation or improving the type mapping could help avoid confusion for others.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3396673970 --> @dosubot[bot] commented on GitHub (Oct 13, 2025): <!-- Greeting --> Hi @ofek-frame! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You're right—the current implementation maps TypeScript literal array types like `${"string" | "number"}[]` to plain string arrays in the generated schema, without enforcing enum-like constraints or validation. This can be misleading, since the type signature suggests stricter validation than what actually happens at the schema level. There isn't special handling for enum arrays or validated string arrays in the schema generation logic; everything gets converted to a string array regardless of the literal type definition [see drizzle.ts implementation](https://github.com/better-auth/better-auth/blob/f4a91d090004d1c24c7d3fa8e7ac8302f249c3e5/packages/cli/src/generators/drizzle.ts). If you need enum-like validation, you'll need to add custom validation logic at the application level for now. This is a gap between the type system and the generated schema, and clarifying this in the documentation or improving the type mapping could help avoid confusion for others. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f019e325-6958-43f1-936a-24f85f91ad32?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/5268)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18830