Skip to content

Using exactOptionalPropertyTypes: true in TSConfig Causes Type Errors in Anonymous Plugin #6127

@portrik

Description

@portrik

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lockedLocked conversations after being closed for 7 days

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions