Inferred type of betterAuth client exceed compiler serialization

Hi, Im getting this typescript error in my project. Any suggestion on how to solve it? `The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.``
11 Replies
discquist
discquistOP2w ago
Anyone stumbled into the same issue? 🤔
Ping
Ping2w ago
have you enabled strict in tsconfig? @discquist https://www.better-auth.com/docs/concepts/typescript#strict-mode
TypeScript | Better Auth
Better Auth TypeScript integration.
discquist
discquistOP2w ago
Yes that's enabled Is there any type i can vast the betterAuth isntance as? That would probably help, but couldn't find.
Big Chunckus
Big Chunckus2w ago
Same error for me
Ping
Ping2w ago
Normally this solves it. Can I see your entire tsconfig?
Big Chunckus
Big Chunckus2w ago
for me it's
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Next.js",
"extends": "./base.json",
"compilerOptions": {
"strict": true,
"plugins": [{ "name": "next" }],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true,
"jsx": "preserve",
"noEmit": true
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Next.js",
"extends": "./base.json",
"compilerOptions": {
"strict": true,
"plugins": [{ "name": "next" }],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowJs": true,
"jsx": "preserve",
"noEmit": true
}
}
and base.json
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"incremental": false,
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "NodeNext",
"moduleDetection": "force",
"moduleResolution": "NodeNext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
}
}
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"incremental": false,
"isolatedModules": true,
"lib": ["es2022", "DOM", "DOM.Iterable"],
"module": "NodeNext",
"moduleDetection": "force",
"moduleResolution": "NodeNext",
"noUncheckedIndexedAccess": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
}
}
Ping
Ping2w ago
Check if you disable declaration if it will work
Big Chunckus
Big Chunckus2w ago
seem to work thank you 🙏
Ping
Ping7d ago
Hello, @discquist , could you try disabling declaration as well?
discquist
discquistOP6d ago
Yeah i'll try that.But unsure if i want to do that since i use a ackend framework (encore.ts) that allows me to generate fully typed client to consume in my frontend. @Ping Yeah, not possilbe for me to disbale declaration in my projet. So i htink one solution would be if i can set the type of the instance or something?
Ping
Ping6d ago
You can set it to ReturnType<typeof betterAuth>, but you won't get any inference for any plugins or other configurations you may have added.

Did you find this page helpful?