Skip to content

[BUG]: drizzle valibot select schema's inferred type does not recognized properties using integer().generatedAlwaysAsIdentity() #4556

@difrisul-dev1

Description

@difrisul-dev1

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.43.1

What version of drizzle-kit are you using?

0.31.1

Other packages

[email protected]

Describe the Bug

The very example on the documentation causes this:

(from https://orm.drizzle.team/docs/valibot)

import { pgTable, text, integer } from 'drizzle-orm/pg-core';
import { createSelectSchema } from 'drizzle-valibot';
import { parse } from 'valibot';
const users = pgTable('users', {
  id: integer().generatedAlwaysAsIdentity().primaryKey(),
  name: text().notNull(),
  age: integer().notNull()
});
const userSelectSchema = createSelectSchema(users);

const rows = await db.select().from(users).limit(1);

// error: Property 'id' is missing in type '{ name: string; age: number; }' but required in type '{ id: number; name: string; age: number; }'. (ts 2741)
const parsed: { id: number; name: string; age: number } = parse(userSelectSchema, rows[0]);

This does not happen, for example, if the id is declared with uuid().defaultRandom(). The DB does return the ID on a query regardless of course, so this is just a typing bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions