Skip to content

Conversation

@xuxucode
Copy link

@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