drizzle-team / drizzle-team/drizzle-orm

[BUG]: From beta release. Nested jsonb and array jsonb types aren't being inferred correctly using drizzle zod

Open
#4,930 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

@beta

### What version of `drizzle-kit` are you using?

@beta

### Other packages

drizzle-zod@0.8.3, zod@4.1.9

### Describe the Bug

Types aren't being inferred correctly from nested jsonb objects and jsonb arrays. This was working in non beta releases. With only 1 level deep it works, any deeper and its inferred as unknown.

```ts

// Array

export const ArraySchema = z.array(z.object({
key: z.string(),
}));

export type ArraySchemaValues = z.infer;

array: jsonb()
.$type()
.default(sql`'[]'::jsonb`)

const TableSchema = createInsertSchema(table)

type TableSchemaValues = z.infer

type Array = TableSchemaValues["array"]

// type inferred

type Array = {
[x: number]: unknown;
length: number;
toString: unknown;
toLocaleString: unknown;
pop: unknown;
push: unknown;
concat: unknown;
join: unknown;
reverse: unknown;
shift: unknown;
slice: unknown;
sort: unknown;
splice: unknown;
unshift: unknown;
indexOf: unknown;
lastIndexOf: unknown;
every: unknown;
some: unknown;
forEach: unknown;
map: unknown;
filter: unknown;
reduce: unknown;
reduceRight: unknown;
find: unknown;
findIndex: unknown;
fill: unknown;
copyWithin: unknown;
entries: unknown;
keys: unknown;
values: unknown;
includes: unknown;
flatMap: unknown;
flat: unknown;
at: unknown;
findLast: unknown;
findLastIndex: unknown;
toReversed: unknown;
toSorted: unknown;
toSpliced: unknown;
with: unknown;
[Symbol.iterator]: unknown;
[Symbol.unscopables]: unknown;
} | undefined

// Nested

export const NestedSchema = z.object({
level1: z.object({
level2: z.object({
level3: z.string(),
}),
}),
});

export type NestedSchemaValues = z.infer;

nested: jsonb()
.$type()
.default(sql`'[]'::jsonb`)

const TableSchema = createInsertSchema(table)

type TableSchemaValues = z.infer

type Nested = TestSchemaValues["nested"];

// type inferred

type Nested = {
level1: unknown;
} | undefined

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.