Skip to content

[beta] Refine RelationsFieldFilter type to prioritize Primitive over Object#5243

Open
xuxucode wants to merge 1 commit intodrizzle-team:betafrom
xuxucode:patch-1
Open

[beta] Refine RelationsFieldFilter type to prioritize Primitive over Object#5243
xuxucode wants to merge 1 commit intodrizzle-team:betafrom
xuxucode:patch-1

Conversation

@xuxucode
Copy link
Copy Markdown

@xuxucode xuxucode commented Jan 10, 2026

Branded types may be both Primitive and Object. For example:

import z from 'zod'

// AppId is both string and object
export type AppId = string & z.$brand<'AppId'>

Currently RelationsFieldFilter<AppId> results in never. It leads to a type error when $type<AppId>() is used in the database schema. For example:

import { db } from '../lib/db'
import { pgTable, uuid } from 'drizzle-orm/pg-core'

export const apps = pgTable('apps', {
  id: uuid().$type<AppId>().primaryKey(),
})

export async function getAppById(appId: AppId) {
  return db.query.apps.findFirst({
    where: {
      id: appId,
    },
  })
}

Error:
image

Prioritizing Primitive over Object in the RelationsFieldFilter definition will fix that

Branded types may be both Primitive and Object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant