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.``
17 Replies
Anyone stumbled into the same issue? 🤔
have you enabled
strict
in tsconfig? @discquist
https://www.better-auth.com/docs/concepts/typescript#strict-modeTypeScript | Better Auth
Better Auth TypeScript integration.
Yes that's enabled
Is there any type i can vast the betterAuth isntance as? That would probably help, but couldn't find.
Same error for me
Normally this solves it. Can I see your entire tsconfig?
for me it's
and base.json
Check if you disable declaration if it will work
seem to work thank you 🙏
Hello, @discquist , could you try disabling
declaration
as well?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?
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.I'm also running into this issue. We've got a monorepo with project references, so I can't turn declarations off (because TS requires declarations for project references).
It's happening to us when I try to add the stripe plugin. It works fine without it. It seems it's the combination of the organization plugin and the stripe plugin, because removing the organization plugin also removes the warning.
If anyone has gotten around this issue, I'd love some pointers in the right direction 🙏
Just here to add a +1 to this. The organization plugin is the culprit, removing other plugins and leaving it in place still displays the error. I assume this is because the organization plugin declaration is about 6500 lines of types. Disabling declaration did not help, however that wouldn't be an option for us anyway, as we are also using a monorepo with project references.
The
ReturnType<typeof betterAuth>
workaround broke a bunch of other types that were based on config, so I wound up with this hack:
This is obviously fragile, but is working for right now.
On version 1.2.12
I think this is mostly a Better-Auth issue, not sure if there are any work-arounds, or not to my knowledge at least.
I'm certain we will fix this in the future, most likely in a major release (since it's possible we will have breaking changes - not 100% on that though) so it might be some time away unfortunately.
+1
+1
I'm getting the same error when trying to add the organization plugin.
Same error, every time i try workaround, i get my self in another issue.