TheEdoRan / next-safe-action

Type safe and validated Server Actions in your Next.js project.
https://next-safe-action.dev
MIT License
2.11k stars 33 forks source link

[BUG] Valibot schema not working #181

Closed pedro757 closed 2 months ago

pedro757 commented 3 months ago

Are you using the latest version of this library?

Is there an existing issue for this?

Describe the bug

I get this error from tsserver:

Argument of type 'ObjectSchema<{ readonly MyField: StringSchema<undefined>; }, undefined>' is not assignable to parameter of type 'ZodType<any, ZodTypeDef, any> | ((prevSchema: undefined) => Promise<ZodType<any, ZodTypeDef, any>>)'. [2345]

Reproduction steps

  1. Create and use an action with valibot like this
    
    "use server";

import { string, object } from "valibot";

const createSchema = object({ MyField: string(), });

export const createSomething = action .schema(createSchema) .action(async function ({ parsedInput }) { // parsedInput is of type unknown });

The error I get is this:

Argument of type 'ObjectSchema<{ readonly MyField: StringSchema; }, undefined>' is not assignable to parameter of type 'ZodType<any, ZodTypeDef, any> | ((prevSchema: undefined) => Promise<ZodType<any, ZodTypeDef, any>>)'. [2345]


It looks like it's expecting a zod type

### Expected behavior

I expected to work with valibot

### Minimal reproduction example

The code is in the description of the issue

### Operating System

Linux

### Library version

7.1

### Next.js version

14.2.4

### Additional context

_No response_
TheEdoRan commented 3 months ago

Need a link to a minimal reproduction example.

TheEdoRan commented 2 months ago

This is related to (either or both):

I'm closing the issue as there are already issues open about this problem.

TheEdoRan commented 2 months ago

Hey @pedro757, please try to update to the latest stable release and set up validation with Valibot. Now next-safe-action ships with built-in support for multiple validation libraries. Related discussion here and docs page here.