next-safe-action: [BUG] Not compatible with Typescript >= 5.5.2
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
- Install Typescript 5.5.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
Operating System
MacOS 14
Library version
7.2.0
Next.js version
14.2.4
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 20
- Comments: 18 (9 by maintainers)
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:
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.
I can confirm schema validations don’t work with typescript 5.5.2, I get
anyfromparsedInputHey! Just to let you know is working for me using TS 5.5 and zod. Thanks for your amazing work!
@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.
Thanks for the reply! I’ve long since updated, love the new version!
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.