[GH-ISSUE #5270] Invalid typing using additionalFields #27523

Closed
opened 2026-04-17 18:34:49 -05:00 by GiteaMirror · 5 comments
Owner

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

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Add additionalFields to user.

user: {
  additionalFields: {
    timeZone: {
      type: "string",
      required: false,
    },
  },
}, 

Current vs. Expected behavior

Results in incorrectly inferred types.

type SignUpInput = Omit<CreateUserInput, "timeZone"> & {
  timeZone: never;
} & { timeZone?: null | undefined };

Signup input expects:

body: {
    name: string;
    email: string;
    password: string;
    image?: string;
    callbackURL?: string;
    rememberMe?: boolean;
} & {
    timeZone: never;
} & {
    timeZone?: null | undefined;
};

What version of Better Auth are you using?

1.3.26

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:50 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6030",
    "release": "25.0.0",
    "cpuCount": 12,
    "cpuModel": "Apple M3 Pro",
    "totalMemory": "18.00 GB",
    "freeMemory": "1.06 GB"
  },
  "node": {
    "version": "v23.2.0",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.2.20"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

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

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

Something changed with the inference of types between version 1.3.18 and 1.3.26.

Originally created by @simohammadi on GitHub (Oct 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5270 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Add additionalFields to user. ``` user: { additionalFields: { timeZone: { type: "string", required: false, }, }, }, ``` ### Current vs. Expected behavior Results in incorrectly inferred types. ``` type SignUpInput = Omit<CreateUserInput, "timeZone"> & { timeZone: never; } & { timeZone?: null | undefined }; ```` Signup input expects: ``` body: { name: string; email: string; password: string; image?: string; callbackURL?: string; rememberMe?: boolean; } & { timeZone: never; } & { timeZone?: null | undefined; }; ``` ### What version of Better Auth are you using? 1.3.26 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:50 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6030", "release": "25.0.0", "cpuCount": 12, "cpuModel": "Apple M3 Pro", "totalMemory": "18.00 GB", "freeMemory": "1.06 GB" }, "node": { "version": "v23.2.0", "env": "development" }, "packageManager": { "name": "bun", "version": "1.2.20" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context Something changed with the inference of types between version 1.3.18 and 1.3.26.
GiteaMirror added the lockedbug labels 2026-04-17 18:34:49 -05:00
Author
Owner

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

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

This is a known limitation in Better Auth 1.3.26 and later: full type inference for additionalFields (like your optional timeZone field) is not yet supported, which can result in incorrect or overly restrictive types in generated input types such as SignUpInput. This change was introduced in recent updates to the type inference logic for additionalFields, and the documentation now includes a warning about this limitation—improved type support is planned for the future [source].

Currently, there is no official workaround for automatic type inference. The best approach is to manually augment or override the inferred types in your codebase where needed, for example by explicitly defining the expected input types for your forms or API calls. Keep an eye on future releases for improved support.

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:3397216503 --> @dosubot[bot] commented on GitHub (Oct 13, 2025): <!-- Greeting --> Hi @simohammadi! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known limitation in Better Auth 1.3.26 and later: full type inference for additionalFields (like your optional timeZone field) is not yet supported, which can result in incorrect or overly restrictive types in generated input types such as SignUpInput. This change was introduced in recent updates to the type inference logic for additionalFields, and the documentation now includes a warning about this limitation—improved type support is planned for the future [[source]](https://github.com/better-auth/better-auth/pull/5146). Currently, there is no official workaround for automatic type inference. The best approach is to manually augment or override the inferred types in your codebase where needed, for example by explicitly defining the expected input types for your forms or API calls. Keep an eye on future releases for improved support. <!-- 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/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1dcf67f7-68f8-488a-af90-0c2ec0daaf03?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/5270)
Author
Owner

@simohammadi commented on GitHub (Oct 13, 2025):

@dosu

Dont think this is a valid answer. The types should not make me as a consumer of the apis have to typecast my inputs into the exact type of what is being inferred.

At least better auth could allow me as a user pass in anything from the typing standpoint, that is a better way of relaxing type support, for whatever reason.

Is it expected that for every additional field I add I need to typecast the property to never | null | undefined?

<!-- gh-comment-id:3397339327 --> @simohammadi commented on GitHub (Oct 13, 2025): @dosu Dont think this is a valid answer. The types should not make me as a consumer of the apis have to typecast my inputs into the exact type of what is being inferred. At least better auth could allow me as a user pass in anything from the typing standpoint, that is a better way of relaxing type support, for whatever reason. Is it expected that for every additional field I add I need to typecast the property to never | null | undefined?
Author
Owner

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

No, it's not expected or intended that you should have to typecast every additional field to never | null | undefined. This is a known limitation in Better Auth 1.3.26 and later—full type inference for additionalFields isn't supported yet, and the types can end up overly restrictive or incorrect for custom fields. There isn't an official way to relax type support or override this behavior right now, and no configuration or utility type exists to globally allow more permissive typing for these fields. The only workaround is to manually augment or override the inferred types in your own code until improved support is released [source].

Other users have run into the same issue, and the consensus is that manual workarounds are necessary for now. If you want to avoid type errors, you can loosen your consumer-side type expectations (for example, using any or declaration merging), but this isn't ideal and should be temporary until the type system is improved.

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:3397348568 --> @dosubot[bot] commented on GitHub (Oct 13, 2025): <!-- Answer --> No, it's not expected or intended that you should have to typecast every additional field to `never | null | undefined`. This is a known limitation in Better Auth 1.3.26 and later—full type inference for `additionalFields` isn't supported yet, and the types can end up overly restrictive or incorrect for custom fields. There isn't an official way to relax type support or override this behavior right now, and no configuration or utility type exists to globally allow more permissive typing for these fields. The only workaround is to manually augment or override the inferred types in your own code until improved support is released [[source]](https://github.com/better-auth/better-auth/pull/5146). Other users have run into the same issue, and the consensus is that manual workarounds are necessary for now. If you want to avoid type errors, you can loosen your consumer-side type expectations (for example, using `any` or declaration merging), but this isn't ideal and should be temporary until the type system is improved. <!-- 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/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6b4ebe62-2bfc-4a58-8bbc-cbc2eb913bb2?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/5270)
Author
Owner

@himself65 commented on GitHub (Oct 13, 2025):

This is fixed in the Canary branch. Will be fixed in the next version

<!-- gh-comment-id:3399357823 --> @himself65 commented on GitHub (Oct 13, 2025): This is fixed in the Canary branch. Will be fixed in the next version
Author
Owner

@eloi24 commented on GitHub (Oct 15, 2025):

Same here in the 1.3.27 the types don't even resolve in the session and user.

<!-- gh-comment-id:3408133890 --> @eloi24 commented on GitHub (Oct 15, 2025): Same here in the 1.3.27 the types don't even resolve in the session and user.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27523