Cannot generate Typebox schema from Drizzle Enum

i just trying to do the same thing as show in the docs here: https://orm.drizzle.team/docs/typebox#select-schema so i just copy and paste this from the docs: import { pgEnum } from "drizzle-orm/pg-core"; import { createInsertSchema } from 'drizzle-typebox' const roles = pgEnum('roles', ['admin', 'basic']); const rolesSchema = createSelectSchema(roles); However, i got this error at createSelectSchema(roles): Argument of type 'PgEnum<["admin", "basic"]>' is not assignable to parameter of type 'Table<TableConfig<Column<any, object, object>>>'. Type 'PgEnum<["admin", "basic"]>' is missing the following properties from type 'Table<TableConfig<Column<any, object, object>>>': _, $inferSelect, $inferInsert, getSQLts(2345) version: "drizzle-orm": "^0.38.2", "drizzle-typebox": "^0.2.0",
Drizzle ORM - drizzle-typebox
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
6 Replies
Mario564
Mario5645mo ago
@The Rumbling Can I see your tsconfig.json file?
The Rumbling
The RumblingOP5mo ago
here is my tsconfig.json
No description
Mario564
Mario5645mo ago
Hmmm, can you try setting the target to ESNext?
The Rumbling
The RumblingOP5mo ago
Thx! i think its fixed for now!
No description
Mario564
Mario5645mo ago
We use ESNext internally in repos, so we had no issues there. Not sure if there's much we can do for it work in earlier ES versions, but glad this at least worked
Newt
Newt6d ago
I'm encountering a type compatibility issue with Drizzle ORM and TypeBox. When using createSchemaFactory from drizzle-typebox with PostgreSQL tables, I'm getting type errors when trying to create schemas. But in Runtime it Works without any Problems, i also Tried to edit my tsconfig to:
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
"$server": ["./src/server.ts"],
"$lib/*": ["./src/lib/*"]
}
},
"include": ["src"]
}
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
"$server": ["./src/server.ts"],
"$lib/*": ["./src/lib/*"]
}
},
"include": ["src"]
}
Versions:
"drizzle-orm": "^0.41.0",
"drizzle-typebox": "^0.3.1",
"drizzle-orm": "^0.41.0",
"drizzle-typebox": "^0.3.1",
The error suggests that the PostgreSQL-specific column types (PgColumn) from my table definition aren't compatible with the generic Column type expected by the schema factory functions:
Argument of type 'PgTableWithColumns<...>' is not assignable to parameter
of type 'Table<...>'. The types of '_.config.columns' are incompatible...
Argument of type 'PgTableWithColumns<...>' is not assignable to parameter
of type 'Table<...>'. The types of '_.config.columns' are incompatible...
Has anyone encountered similar type mismatches when using PostgreSQL-specific types with the schema factory? Is there a proper way to handle this without type assertions? My Code: Code:
import { table } from "$lib/db/schema.ts";
import { createSchemaFactory } from "drizzle-typebox";
import { t } from "elysia";

const { createInsertSchema, createSelectSchema, createUpdateSchema } = createSchemaFactory({ typeboxInstance: t });

const Content = t.Object({
text: t.String(),
data: t.String(),
});

const MessageExample = t.Object({
user: t.String(),
content: Content,
});

export const AgentSchema = {
//The Error Apears here:
insert: createInsertSchema(table.agent, {
messageExamples: t.Array(t.Array(MessageExample)),
}),
//The Error Apears here:
select: createSelectSchema(table.agent, {
messageExamples: t.Array(t.Array(MessageExample)),
}),
//The Error Apears here:
update: createUpdateSchema(table.agent, {
messageExamples: t.Array(t.Array(MessageExample)),
}),
} as const;
import { table } from "$lib/db/schema.ts";
import { createSchemaFactory } from "drizzle-typebox";
import { t } from "elysia";

const { createInsertSchema, createSelectSchema, createUpdateSchema } = createSchemaFactory({ typeboxInstance: t });

const Content = t.Object({
text: t.String(),
data: t.String(),
});

const MessageExample = t.Object({
user: t.String(),
content: Content,
});

export const AgentSchema = {
//The Error Apears here:
insert: createInsertSchema(table.agent, {
messageExamples: t.Array(t.Array(MessageExample)),
}),
//The Error Apears here:
select: createSelectSchema(table.agent, {
messageExamples: t.Array(t.Array(MessageExample)),
}),
//The Error Apears here:
update: createUpdateSchema(table.agent, {
messageExamples: t.Array(t.Array(MessageExample)),
}),
} as const;

Did you find this page helpful?