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

Unexpected type ZodEffects #15

Closed
binajmen opened this issue Feb 17, 2022 · 2 comments
Closed

Unexpected type ZodEffects #15

binajmen opened this issue Feb 17, 2022 · 2 comments

Comments

@binajmen
Copy link

binajmen commented Feb 17, 2022

I have this schema to test the content of a JSON value.

import { z } from "zod";

const schema = z.object({
  name: z.string().refine((val) => {
    const values = Object.values(JSON.parse(val));
    return (
      values.length > 0 &&
      values.some((v) => typeof v === "string" && v.length > 0)
    );
  }, "You must fill in at least one language")
});

// error
schema.parse({ name: '{""}' });
schema.parse({ name: '{"en":""}' });
schema.parse({ name: '{"en":"","fr":""}' });

// success
schema.parse({ name: '{"en":"Game"}' });
schema.parse({ name: '{"en":"Game","fr":""}' });
schema.parse({ name: '{"en":"Game","fr":"Jeu"}' });

The schema works, but remix-params-helper does not seem to like it..

Error: Unexpected type ZodEffects for key name
    at processDef (/Users/benjamin/Projects/horeka/node_modules/remix-params-helper/dist/cjs/helper.js:149:15)
    at parseParams (/Users/benjamin/Projects/horeka/node_modules/remix-params-helper/dist/cjs/helper.js:19:9)
    at getParamsInternal (/Users/benjamin/Projects/horeka/node_modules/remix-params-helper/dist/cjs/helper.js:50:9)
    at getParams (/Users/benjamin/Projects/horeka/node_modules/remix-params-helper/dist/cjs/helper.js:84:12)
    at action (/Users/benjamin/Projects/horeka/build/index.js:993:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.callRouteAction (/Users/benjamin/Projects/horeka/node_modules/@remix-run/server-runtime/data.js:36:14)
    at async handleDataRequest (/Users/benjamin/Projects/horeka/node_modules/@remix-run/server-runtime/server.js:110:18)
    at async requestHandler (/Users/benjamin/Projects/horeka/node_modules/@remix-run/server-runtime/server.js:45:20)
    at async /Users/benjamin/Projects/horeka/node_modules/@remix-run/express/server.js:45:22
@kiliman
Copy link
Owner

kiliman commented Feb 17, 2022

Thanks. The helper walks the schema to coerce your input into the schema. Apparently it's not handling the refine() function.

Thanks for the repro. I'll get this fixed.

@binajmen
Copy link
Author

Sir, you are awesome! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants