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] Not compatible with Typescript >= 5.5.2 #180

Closed
2 tasks done
Talent30 opened this issue Jun 20, 2024 · 16 comments
Closed
2 tasks done

[BUG] Not compatible with Typescript >= 5.5.2 #180

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

Comments

@Talent30
Copy link

Talent30 commented Jun 20, 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

parsedInput returning any, schema defined by Zod

Will provide a minimal repo soon.

Reproduction steps

  1. Install Typescript 5.5.2
  2. Create a safe action with Zod schema, check the type of parsedInput

Expected behavior

parsedInput should have the correct type information

Minimal reproduction example

Code Sandbox link

Operating System

MacOS 14

Library version

7.2.0

Next.js version

14.2.4

Additional context

No response

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

Will look into it soon, thanks.

@pedro757
Copy link

pedro757 commented Jun 21, 2024

I can confirm schema validations don't work with typescript 5.5.2, I get any from parsedInput

@TheEdoRan
Copy link
Owner

After some tests, I identified the problem in TypeSchema, which breaks with TypeScript 5.5. I've just opened an issue on the TypeSchema repo for this bug:

@TheEdoRan
Copy link
Owner

Might be related to:

@TheEdoRan TheEdoRan pinned this issue Jun 24, 2024
@RolandRFuchs92
Copy link

I know this is a pretty new issue, but a quick easy workaround for me was to just downgrade typescript. I just locked at typescript 5.4.5 (I use the LSP that comes with Mason) for now, it seems to work perfectly.

@TheEdoRan
Copy link
Owner

@RolandRFuchs92 yes, the workaround is to downgrade to TypeScript v5.4. The issue appears to be related to a compiler change in TS 5.5.2, which broke ts-patch and so TypeSchema as well.

@TheEdoRan
Copy link
Owner

I've just released next-safe-action v7.1.4-experimental.1, that should work fine with TypeScript 5.5. Note that this version only works with Zod, it's essentially the same codebase without TypeSchema support, as it's currently preventing the ability to upgrade to TS 5.5.

So, if you're using Zod and TS 5.5, you can install experimental next-safe-action with this command:

npm i next-safe-action@experimental # or pnpm, yarn

P.S.: Even though the tag is named "experimental", as explained above the codebase is essentially the same as the stable v7. It's named like that because I don't think this will be an actual library change, as it's nice to have multiple validation libraries support. However, it's also nice to use the latest TS version, so until TypeSchema is compatible with it, I think this is a good solution.

@TheEdoRan TheEdoRan changed the title [BUG] Not compatible with Typescript 5.5.2 [BUG] Not compatible with Typescript >= 5.5.2 Jul 2, 2024
@damjtoh
Copy link

damjtoh commented Jul 3, 2024

I've just released next-safe-action v7.1.4-experimental.1, that should work fine with TypeScript 5.5. Note that this version only works with Zod, it's essentially the same codebase without TypeSchema support, as it's currently preventing the ability to upgrade to TS 5.5.

So, if you're using Zod and TS 5.5, you can install experimental next-safe-action with this command:

npm i next-safe-action@experimental # or pnpm, yarn

P.S.: Even though the tag is named "experimental", as explained above the codebase is essentially the same as the stable v7. It's named like that because I don't think this will be an actual library change, as it's nice to have multiple validation libraries support. However, it's also nice to use the latest TS version, so until TypeSchema is compatible with it, I think this is a good solution.

Hey! Just to let you know is working for me using TS 5.5 and zod. Thanks for your amazing work!

@mattiaz9
Copy link

I'm trying the experimental version, but I can't destruct the response because is possibly undefined.

@TheEdoRan
Copy link
Owner

@mattiaz9 that's not an experimental version bug, it's the expected behavior since v7.0.0. The explanation for that can be found here.

@mattiaz9
Copy link

@mattiaz9 that's not an experimental version bug, it's the expected behavior since v7.0.0. The explanation for that can be found here.

I see. I was previously using a pre-release of v7 and it wasn't yet the case, so I thought it was an error.

It didn't help the fact that in the docs that behavior is not shown.
For instance in this example res is destructed without checking if undefined:
https://next-safe-action.dev/docs/getting-started#3-import-and-execute-the-action

@TheEdoRan
Copy link
Owner

@mattiaz9

It didn't help the fact that in the docs that behavior is not shown.

Fixed. It was left over from v6 docs.

anarkrypto added a commit to nanopay/nanopay.me that referenced this issue Jul 14, 2024
@aniketbiprojit
Copy link

This should probably be added to docs as well if not already there.

@TheEdoRan
Copy link
Owner

TheEdoRan commented Jul 15, 2024

@aniketbiprojit https://next-safe-action.dev/docs/troubleshooting#schema-and-parsedinput-are-typed-any-broken-types-and-build-issues

But I'll add a note on the getting started page too, soon.

Also, I'm thinking of implementing a built-in system to support a small number of validation libraries (zod, valibot, yup), instead of relying on a third party library.

@TheEdoRan
Copy link
Owner

TheEdoRan commented Jul 20, 2024

This issue should be solved in v7.2.0. next-safe-action now ships with a built-in system for supporting multiple validation libraries, at this time Zod (the default one), Valibot and Yup. You can now use them even with the Edge Runtime and obviously with TS >= 5.5. More information about that in this discussion and on this page of the website.

Please let me know if you encounter any bugs when updating to v7.2.0, thanks!

EDIT: Be sure to update to v7.2.1, which solves a build bug introduced in v7.2.0.

@benjick
Copy link

benjick commented Jul 22, 2024

Any chance getting this fixed in v6 too?

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

8 participants