[GH-ISSUE #3205] Bug with type inference for nullish fields #18147

Closed
opened 2026-04-15 16:31:54 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @rebasecase on GitHub (Jun 28, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3205

Not entirely sure where this bug exists it may be with typescript or zod, or elsewhere.

const authSession = await auth.api.getSession({ headers });
event.locals.authUser = authSession?.user;

Intellisense says that it is string | null | undefined | undefined

Image

However, dereferencing authSession?.user becomes, correctly, string | null | undefined

Originally created by @rebasecase on GitHub (Jun 28, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3205 Not entirely sure where this bug exists it may be with typescript or zod, or elsewhere. ``` const authSession = await auth.api.getSession({ headers }); event.locals.authUser = authSession?.user; ``` Intellisense says that it is `string | null | undefined | undefined` ![Image](https://github.com/user-attachments/assets/77d7a8a2-7dfc-49ca-9387-3b26092f8b57) However, dereferencing `authSession?.user` becomes, correctly, `string | null | undefined`
GiteaMirror added the lockedbug labels 2026-04-15 16:31:54 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Jul 17, 2025):

The extra undefined you're seeing is just a weird thing from the editor , probably caused by how TypeScript combines types behind the scenes (like through Zod or similar). It’s not actually a bug or a real problem with the type itself since TypeScript treats duplicate types as one.

<!-- gh-comment-id:3085698585 --> @Kinfe123 commented on GitHub (Jul 17, 2025): The extra undefined you're seeing is just a weird thing from the editor , probably caused by how TypeScript combines types behind the scenes (like through Zod or similar). It’s not actually a bug or a real problem with the type itself since TypeScript treats duplicate types as one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18147