Cannot pass custom fields defined in additionalFields to auth.api.signUpEmail() body due to incorrect TypeScript inference #2466

Open
opened 2026-03-13 09:56:32 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @GreedyPirate on GitHub (Dec 5, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm using Better Auth with custom user fields configured via additionalFields:

user: {
  additionalFields: {
    country: { type: "string", required: true },
    // ... other fields
  }
}

According to the documentation, I should be able to pass these fields directly in the signup server side call like this:

await auth.api.signUpEmail({
  body: {
    email: "...",
    password: "...",
    name: "...",
    country: "US",        // ← custom field
  }
});

Current vs. Expected behavior

TS2769: No overload matches this call. The last overload gave the following error. Object literal may only specify known properties, and country does not exist in type

What version of Better Auth are you using?

1.4.5

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 10 Pro",
    "release": "10.0.19045",
    "cpuCount": 20,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-12700",
    "totalMemory": "47.75 GB",
    "freeMemory": "24.39 GB"
  },
  "node": {
    "version": "v22.13.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.6"
    },
    {
      "name": "react",
      "version": "19.2.0"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.5",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import {betterAuth} from "better-auth"

export const auth = betterAuth({
    emailAndPassword: {
        enabled: true
    },
    user: {
        deleteUser: {
            enabled: true
        },
        additionalFields: {
            country: {
                type: "string",
                required: true
            }
        },
    }
});

Additional context

No response

Originally created by @GreedyPirate on GitHub (Dec 5, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm using Better Auth with custom user fields configured via additionalFields: ```ts user: { additionalFields: { country: { type: "string", required: true }, // ... other fields } } ``` According to the documentation, I should be able to pass these fields directly in the signup **server side** call like this: ``` await auth.api.signUpEmail({ body: { email: "...", password: "...", name: "...", country: "US", // ← custom field } }); ``` ### Current vs. Expected behavior `TS2769: No overload matches this call. The last overload gave the following error. Object literal may only specify known properties, and country does not exist in type` ### What version of Better Auth are you using? 1.4.5 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 10 Pro", "release": "10.0.19045", "cpuCount": 20, "cpuModel": "12th Gen Intel(R) Core(TM) i7-12700", "totalMemory": "47.75 GB", "freeMemory": "24.39 GB" }, "node": { "version": "v22.13.1", "env": "development" }, "packageManager": { "name": "npm", }, "frameworks": [ { "name": "next", "version": "16.0.6" }, { "name": "react", "version": "19.2.0" } ], "databases": null, "betterAuth": { "version": "^1.4.5", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import {betterAuth} from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, user: { deleteUser: { enabled: true }, additionalFields: { country: { type: "string", required: true } }, } }); ``` ### Additional context _No response_
GiteaMirror added the staleenhancement labels 2026-03-13 09:56:32 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 5, 2025):

It looks like the custom additionalFields (like "country") aren’t being correctly picked up during TypeScript type inference for the signUpEmail call. This is similar to earlier reports where extended schema fields were not properly inferred by TS, so the API signature doesn’t accept the extra field without a workaround [1]. As a next step, you might try explicitly augmenting or casting the types for the request body in your server-side signup call. For example, adding a type assertion so that TypeScript recognizes your additional properties could work as a temporary fix, while we work on a more permanent update. Have you tried that approach, or do you have other details that might help clarify the issue further? tag @better-auth-agent if you would like an answer from the Agent

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Dec 5, 2025): It looks like the custom additionalFields (like "country") aren’t being correctly picked up during TypeScript type inference for the signUpEmail call. This is similar to earlier reports where extended schema fields were not properly inferred by TS, so the API signature doesn’t accept the extra field without a workaround [[1]](https://github.com/better-auth/better-auth/issues/6446). As a next step, you might try explicitly augmenting or casting the types for the request body in your server-side signup call. For example, adding a type assertion so that TypeScript recognizes your additional properties could work as a temporary fix, while we work on a more permanent update. Have you tried that approach, or do you have other details that might help clarify the issue further? tag @better-auth-agent if you would like an answer from the Agent _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 5, 2025):

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

This is a known TypeScript inference limitation in Better Auth v1.4.5. Even though additionalFields like country are accepted and validated at runtime in signUpEmail, the TypeScript types for the API call do not automatically include these custom fields, so you get a TS2769 error when passing them in the body. This happens because the type definitions for signUpEmail's body don't dynamically reflect your additionalFields config, even though the runtime logic does support them (source).

Recent PRs (like #6287) have improved runtime support and API responses for additional fields, but as of now, TypeScript still requires a workaround. The recommended options are:

  • Use //@ts-expect-error above the body object when passing custom fields (example).
  • Use explicit type casting when exporting your auth instance to help with type inference:
    export const auth = betterAuth(authConfig) as ReturnType<typeof betterAuth<typeof authConfig>>;
    
  • For more portable type inference, use typeof auth.$Infer.Session.user and typeof auth.$Infer.Session.session for your custom user/session types (reference).

Until the type definitions are fully improved, these workarounds are the best way to pass custom fields to signUpEmail without breaking type safety elsewhere. You can track progress and related discussions in issue #1194 and issue #5637.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 5, 2025): <!-- Greeting --> Hi @GreedyPirate! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known TypeScript inference limitation in Better Auth v1.4.5. Even though additionalFields like country are accepted and validated at runtime in signUpEmail, the TypeScript types for the API call do not automatically include these custom fields, so you get a TS2769 error when passing them in the body. This happens because the type definitions for signUpEmail's body don't dynamically reflect your additionalFields config, even though the runtime logic does support them ([source](https://github.com/better-auth/better-auth/blob/be00f10cad5bbad5a0dababa4b836a3d95ce7747/packages/better-auth/src/api/routes/sign-up.ts#L14-L238)). Recent PRs (like [#6287](https://github.com/better-auth/better-auth/pull/6287)) have improved runtime support and API responses for additional fields, but as of now, TypeScript still requires a workaround. The recommended options are: - Use //@ts-expect-error above the body object when passing custom fields ([example](https://github.com/better-auth/better-auth/pull/5042)). - Use explicit type casting when exporting your auth instance to help with type inference: ```ts export const auth = betterAuth(authConfig) as ReturnType<typeof betterAuth<typeof authConfig>>; ``` - For more portable type inference, use typeof auth.$Infer.Session.user and typeof auth.$Infer.Session.session for your custom user/session types ([reference](https://github.com/better-auth/better-auth/issues/5637)). Until the type definitions are fully improved, these workarounds are the best way to pass custom fields to signUpEmail without breaking type safety elsewhere. You can track progress and related discussions in [issue #1194](https://github.com/better-auth/better-auth/issues/1194) and [issue #5637](https://github.com/better-auth/better-auth/issues/5637). <!-- 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/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6fff6586-8fe8-4e60-8c29-ffc92c286336?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20TypeScript%20inference%20limitation%20in%20Better%20Auth%20v1.4.5.%20Even%20though%20additionalFields%20like%20country%20are%20accepted%20and%20validated%20at%20runtime%20in%20signUpEmail%2C%20the%20TypeScript%20types%20for%20the%20API%20call%20do%20not%20automatically%20include%20these%20custom%20fields%2C%20so%20you%20get%20a%20TS2769%20error%20when%20passing%20them%20in%20the%20body.%20This%20happens%20because%20the%20type%20definitions%20for%20signUpEmail%27s%20body%20don%27t%20dynamically%20reflect%20your%20additionalFields%20config%2C%20even%20though%20the%20runtime%20logic%20does%20support%20them%20%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/be00f10cad5bbad5a0dababa4b836a3d95ce7747/packages/better-auth/src/api/routes/sign-up.ts%23L14-L238%29%29.%0A%0ARecent%20PRs%20%28like%20%5B%236287%5D%28https%3A//github.com/better-auth/better-auth/pull/6287%29%29%20have%20improved%20runtime%20support%20and%20API%20responses%20for%20additional%20fields%2C%20but%20as%20of%20now%2C%20TypeScript%20still%20requires%20a%20workaround.%20The%20recommended%20options%20are%3A%0A%0A-%20Use%20//%40ts-expect-error%20above%20the%20body%20object%20when%20passing%20custom%20fields%20%28%5Bexample%5D%28https%3A//github.com/better-auth/better-auth/pull/5042%29%29.%0A-%20Use%20explicit%20type%20casting%20when%20exporting%20your%20auth%20instance%20to%20help%20with%20type%20inference%3A%0A%20%20%60%60%60ts%0A%20%20export%20const%20auth%20%3D%20betterAuth%28authConfig%29%20as%20ReturnType%3Ctypeof%20betterAuth%3Ctypeof%20authConfig%3E%3E%3B%0A%20%20%60%60%60%0A-%20For%20more%20portable%20type%20inference%2C%20use%20typeof%20auth.%24Infer.Session.user%20and%20typeof%20auth.%24Infer.Session.session%20for%20your%20custom%20user/session%20types%20%28%5Breference%5D%28https%3A//github.com/better-auth/better-auth/issues/5637%29%29.%0A%0AUntil%20the%20type%20definitions%20are%20fully%20improved%2C%20these%20workarounds%20are%20the%20best%20way%20to%20pass%20custom%20fields%20to%20signUpEmail%20without%20breaking%20type%20safety%20elsewhere.%20You%20can%20track%20progress%20and%20related%20discussions%20in%20%5Bissue%20%231194%5D%28https%3A//github.com/better-auth/better-auth/issues/1194%29%20and%20%5Bissue%20%235637%5D%28https%3A//github.com/better-auth/better-auth/issues/5637%29.)&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/6553)
Author
Owner

@AntonVishal commented on GitHub (Dec 6, 2025):

Hey @GreedyPirate you need to add input: true

type: "string",
required: true,
input: true,
@AntonVishal commented on GitHub (Dec 6, 2025): Hey @GreedyPirate you need to add `input: true` ``` type: "string", required: true, input: true, ```
Author
Owner

@dosubot[bot] commented on GitHub (Mar 7, 2026):

Hi, @GreedyPirate. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported a TypeScript error when passing custom fields like "country" to auth.api.signUpEmail() in Better Auth v1.4.5.
  • The issue stems from TypeScript types not recognizing these custom fields despite runtime support.
  • Maintainers confirmed this is a known TypeScript inference limitation and suggested workarounds such as type assertions, //@ts-expect-error, or explicit casting of the auth instance.
  • Recent PRs have improved runtime handling of additional fields, but full TypeScript type support for additionalFields is still pending.
  • Advice was also given to ensure custom fields include input: true in their type definitions.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here.
  • If I don’t hear back within 7 days, this issue will be automatically closed.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Mar 7, 2026): Hi, @GreedyPirate. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported a TypeScript error when passing custom fields like "country" to `auth.api.signUpEmail()` in Better Auth v1.4.5. - The issue stems from TypeScript types not recognizing these custom fields despite runtime support. - Maintainers confirmed this is a known TypeScript inference limitation and suggested workarounds such as type assertions, `//@ts-expect-error`, or explicit casting of the auth instance. - Recent PRs have improved runtime handling of additional fields, but full TypeScript type support for `additionalFields` is still pending. - Advice was also given to ensure custom fields include `input: true` in their type definitions. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here. - If I don’t hear back within 7 days, this issue will be automatically closed. Thanks for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2466