[GH-ISSUE #6127] Using exactOptionalPropertyTypes: true in TSConfig Causes Type Errors in Anonymous Plugin #10425

Closed
opened 2026-04-13 06:32:52 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @portrik on GitHub (Nov 20, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6127

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Here's the full minimal reproduction project, using the documented usage of the plugin:

package.json

{
	"name": "repro",
	"version": "1.0.0",
	"type": "module",
	"scripts": {
		"types": "tsc --noEmit"
	},
	"devDependencies": {
		"typescript": "5.9.3"
	},
	"dependencies": {
		"better-auth": "1.3.34"
	}
}

tsconfig.json

{
	"compilerOptions": {
		"target": "ESNext",
		"module": "esnext",
		"moduleResolution": "bundler",

		"skipLibCheck": true,
		"noEmit": true,
		"strictNullChecks": true,
		"exactOptionalPropertyTypes": true
	}
}

src/index.ts

import { betterAuth } from "better-auth";
import { anonymous } from "better-auth/plugins";

const auth = betterAuth({
	plugins: [anonymous()], // Produces the type error
});

export { auth };

Current vs. Expected behavior

When running the npm run types command, I would expect the TypeScript compiler to produce no errors. However, the highlighted line produces the following error:

Type '{ id: "anonymous"; endpoints: { signInAnonymous: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "POST" | undefined; } & { query?: Record<string, any> | undefined; } & ... 4 more ... & { ...; }) | undefined): Promise<...>; options: { ...;...' is not assignable to type 'BetterAuthPlugin'.
The types of 'hooks.after' are incompatible between these types.

What version of Better Auth are you using?

1.3.34

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041",
    "release": "25.1.0",
    "cpuCount": 14,
    "cpuModel": "Apple M4 Pro",
    "totalMemory": "48.00 GB",
    "freeMemory": "7.90 GB"
  },
  "node": {
    "version": "v24.10.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.1"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "1.3.34",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { anonymous } from "better-auth/plugins";

const auth = betterAuth({
	plugins: [anonymous()], // Produces the type error
});

export { auth };

Additional context

The type error only appears when exactOptionalPropertyTypes in tsconfig.json is set to true. With the option set to false, the type check passes successfully. It affects both backend and frontend parts.

I have tracked the issue back a few versions, and this error started appearing from 1.3.28 onward. 1.3.27 is working as expected without any type errors. Looking at the 1.3.28 changelog, I don't see an immediate cause of the issue. But I have only taken a brief look.

Originally created by @portrik on GitHub (Nov 20, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6127 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Here's the full minimal reproduction project, [using the documented usage of the plugin](https://www.better-auth.com/docs/plugins/anonymous): `package.json` ```json { "name": "repro", "version": "1.0.0", "type": "module", "scripts": { "types": "tsc --noEmit" }, "devDependencies": { "typescript": "5.9.3" }, "dependencies": { "better-auth": "1.3.34" } } ``` `tsconfig.json` ```json { "compilerOptions": { "target": "ESNext", "module": "esnext", "moduleResolution": "bundler", "skipLibCheck": true, "noEmit": true, "strictNullChecks": true, "exactOptionalPropertyTypes": true } } ``` `src/index.ts` ```typescript import { betterAuth } from "better-auth"; import { anonymous } from "better-auth/plugins"; const auth = betterAuth({ plugins: [anonymous()], // Produces the type error }); export { auth }; ``` ### Current vs. Expected behavior When running the `npm run types` command, I would expect the TypeScript compiler to produce no errors. However, the highlighted line produces the following error: ``` Type '{ id: "anonymous"; endpoints: { signInAnonymous: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "POST" | undefined; } & { query?: Record<string, any> | undefined; } & ... 4 more ... & { ...; }) | undefined): Promise<...>; options: { ...;...' is not assignable to type 'BetterAuthPlugin'. The types of 'hooks.after' are incompatible between these types. ``` ### What version of Better Auth are you using? 1.3.34 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041", "release": "25.1.0", "cpuCount": 14, "cpuModel": "Apple M4 Pro", "totalMemory": "48.00 GB", "freeMemory": "7.90 GB" }, "node": { "version": "v24.10.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.1" }, "frameworks": null, "databases": null, "betterAuth": { "version": "1.3.34", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { anonymous } from "better-auth/plugins"; const auth = betterAuth({ plugins: [anonymous()], // Produces the type error }); export { auth }; ``` ### Additional context The type error only appears when `exactOptionalPropertyTypes` in `tsconfig.json` is set to `true`. With the option set to `false`, the type check passes successfully. **It affects both backend and frontend parts**. I have tracked the issue back a few versions, and this error started appearing from `1.3.28` onward. `1.3.27` is working as expected without any type errors. Looking at the [1.3.28 changelog](https://github.com/better-auth/better-auth/releases/tag/v1.3.28), I don't see an immediate cause of the issue. But I have only taken a brief look.
GiteaMirror added the locked label 2026-04-13 06:32:52 -05:00
Author
Owner

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

Hi there! Thanks for reporting this issue. Based on your description, it looks like a regression related to how the anonymous plugin’s types are handled when TypeScript’s exactOptionalPropertyTypes option is enabled—a change that appeared starting with version 1.3.28. As a temporary workaround, you might consider downgrading to 1.3.27 or disabling that option until we resolve the type incompatibility. In the meantime, please share a minimal reproduction (unless you’ve already linked one) so that we can further investigate the underlying cause. Tag @better-auth-agent if you would like an answer from the Agent. What additional details can you provide about your development environment that might help us pinpoint the issue further?

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3557608251 --> @better-auth-agent[bot] commented on GitHub (Nov 20, 2025): Hi there! Thanks for reporting this issue. Based on your description, it looks like a regression related to how the anonymous plugin’s types are handled when TypeScript’s exactOptionalPropertyTypes option is enabled—a change that appeared starting with version 1.3.28. As a temporary workaround, you might consider downgrading to 1.3.27 or disabling that option until we resolve the type incompatibility. In the meantime, please share a minimal reproduction (unless you’ve already linked one) so that we can further investigate the underlying cause. Tag @better-auth-agent if you would like an answer from the Agent. What additional details can you provide about your development environment that might help us pinpoint the issue further? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@himself65 commented on GitHub (Nov 20, 2025):

I believe we already fixed this in 1.4. We will release a version tmr. Please lmk if it's not working again

<!-- gh-comment-id:3560600891 --> @himself65 commented on GitHub (Nov 20, 2025): I believe we already fixed this in 1.4. We will release a version tmr. Please lmk if it's not working again
Author
Owner

@portrik commented on GitHub (Nov 24, 2025):

I have just tried 1.4.1 and the type issues are gone 👍

<!-- gh-comment-id:3569408301 --> @portrik commented on GitHub (Nov 24, 2025): I have just tried `1.4.1` and the type issues are gone 👍
Author
Owner

@himself65 commented on GitHub (Nov 24, 2025):

Thanks for the feedback

<!-- gh-comment-id:3569531790 --> @himself65 commented on GitHub (Nov 24, 2025): Thanks for the feedback
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10425