How to handle optional params

I'm using BetterAuth + Drizzle, and I have for instance session defined as

...
  ipAddress: text("ip_address"), // can be NULL
...


so when I do

export type Session = typeof session.$inferSelect;


I have Session with ipAddress: string | null

but in BetterAuth API I do

    const sessionInfos = await auth.api.getSession({
      headers: c.req.raw.headers,
    });
    const session = sessionInfos.session;


but here session has a type

...
ipAddress?: string | null | undefined | undefined
...


so I guess it tries to type it as an optional field, instead of just saying that it can be string | null, or instead of just "coercing" null to undefined

is that expected? can we use something cleaner?

can I always assume that ipAddress will be string | null and therefore cast it as a Session ?
Was this page helpful?