Skip to content

Zod not working correcly in V3 schema #2927

@Phu1237

Description

@Phu1237

Environment

Nuxt project info: 11:18:23 AM



Reproduction

  1. Using the config below: content.config.ts
import {defineCollection, defineContentConfig, z} from '@nuxt/content'

export default defineContentConfig({
    collections: {
        blog: defineCollection({
            // Load every file inside the `content` directory
            source: 'blog/**',
            // Specify the type of content in this collection
            type: 'page',
            schema: z.object({
                badge: z.string(),
                image: z.string(),
                tags: z.array(z.string()),
                published: z.boolean(),
                createdAt: z.string().datetime(),
                updatedAt: z.string().datetime(),
            })
        }),
    }
})
  1. Code
        if (options.published !== undefined) {
            // zod use 1 and 0 as boolean
            const published = options.published ? 1 : 0;
            query = query.where("published", '=', published);
        }
        if (options.latest !== undefined) {
            query = query.order('updatedAt', "DESC")
        }

Image

  1. Markdown
---
title: Example title
description: This is example description
badge:
image: /assets/images/coming-soon.jpg
tags:
  - Example
published: false
createdAt: 2025-01-01 00:00
updatedAt: 2025-01-01 00:00
---

## Example title

Nothing here yet. Comeback later.

Bugs:
1. order() not able to use the field in schemas
2. z.boolean() result to numberr 0/1 not boolean false/ true

Describe the bug

1. Bug 1: order() not able to use the field in schemas
When using order with field in schemas it show the below error

Argument of type 'string' is not assignable to parameter of type 'keyof Collections[T]'.
Type '"updatedAt"' is not assignable to type '"extension" | "path" | "title" | "description" | "seo" | "body" | "navigation" | "id" | "stem" | "meta"'.
Image

2. Bug 2: z.boolean() result to numberr 0/1 not boolean false/ true
Image

Additional context

I also see that nuxt/content don't have any total attribute when get from collection so that I can't create paginate and skip() will be useless because it can't count and paginate

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions