Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] TypeScript issue with parsedInput in useAction Hook #174

Closed
2 tasks done
hadrysm opened this issue Jun 16, 2024 · 8 comments
Closed
2 tasks done

[BUG] TypeScript issue with parsedInput in useAction Hook #174

hadrysm opened this issue Jun 16, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@hadrysm
Copy link

hadrysm commented Jun 16, 2024

Are you using the latest version of this library?

  • I verified that the issue exists in the latest next-safe-action release

Is there an existing issue for this?

  • I have searched the existing issues and found nothing that matches

Describe the bug

Hi, I encountered a TypeScript error. The type for my object, which I am validating using zod, is always any.

Reproduction steps

My action with zod:

"use server";
import { createSafeActionClient } from "next-safe-action";
import { z } from "zod";
import { db } from "~/server/db";
import { feedbacks } from "~/server/db/schema";

const action = createSafeActionClient();

const createFeedbackSchema = z.object({
  message: z
    .string()
    .min(10, {
      message: "Message must be at least 10 characters.",
    })
    .max(256, {
      message: "Message must not be longer than 256 characters.",
    }),
});

export const myCallback = action
  .schema(createFeedbackSchema)
  .action(async ({ parsedInput: { message } }) => {
    await db.insert(feedbacks).values({ message, userId: "user-id" });

    return {
      message: "Thank you! Your message has been sent.",
    };
  });

parsedInput is of type any:
Screenshot 2024-06-17 at 00 39 46

The same issue occurs in the component where I use the useAction hook:

Screenshot 2024-06-17 at 00 45 19

Expected behavior

My type for parsedInput should be:

 interface Input {
    message: string;
  }

Minimal reproduction example

See reproduction steps

Operating System

macOs

Library version

7.0.2

Next.js version

14.2.1

Additional context

No response

@hadrysm hadrysm added the bug Something isn't working label Jun 16, 2024
@TheEdoRan
Copy link
Owner

Need a link to a repo with a minimal reproduction example, thanks.

@vidforstner
Copy link

Hi, I'm running into the same issue on Windows.

Here is a minimal reproduction example

@coreybain
Copy link

was having the same issue - check VS code is using your workspace typescript version not the editors - that fixed it for me

@TheEdoRan
Copy link
Owner

@vidforstner thanks for the link. However, I can't reproduce the issue:

image

As @coreybain already said, this could be caused by a TypeScript version mismatch, see:

@laurent512
Copy link

Strange, I also have some typescript issues, but related to destructuring the result of an action
image

@TheEdoRan
Copy link
Owner

@laurent512 is this the same issue as #175?

@TheEdoRan
Copy link
Owner

@hadrysm If this is related to TS 5.5.2 can we close this issue in favor of this other one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants