question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to check if subject is ZodObject?

See original GitHub issue

At the moment I am doing:

const foo = z.object({
  name: z.string(),
});

console.log(foo?._def?.typeName === 'ZodObject');

Though this relies on accessing an internal property.

For context, it is needed to make https://github.com/gajus/slonik/issues/364 work.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
scotttrinhcommented, Oct 7, 2022

I wonder if this is a case of the remix library having a different copy of Zod installed which would cause instanceof checks to fail.

0reactions
miguelespinozacommented, Oct 7, 2022

Here’s some context:

// The zod object I'm creating
const RequestParamSchema = z.object({
  a: z.string().min(1),
  b: z.string().min(1),
  c: z.string().min(1),
  d: z.string().min(1),
});

// Using remix-params-helper to handle the validationg
const params = getParams(event.body, RequestParamSchema);

Here’s the line in question: https://github.com/kiliman/remix-params-helper/blob/main/src/helper.ts#L28

After some digging, this is an esbuild configuration issue. For anyone bumping into this, this is what my serverless.yml config file looks like:

esbuild:
    external:
       - zod
       - remix-params-helper
Read more comments on GitHub >

github_iconTop Results From Across the Web

colinhacks/zod: TypeScript-first schema validation ... - GitHub
By default Zod object schemas strip out unrecognized keys during parsing. You can disallow unknown keys with .strict() . If there are any...
Read more >
Data validation with automatic typing using zod - CodeX Team
1. Validate without description a mountain of different if, instanceof, typeof and other things. 2. Have TypeScript types to represent the data we...
Read more >
Schema validation in TypeScript with Zod - LogRocket Blog
In this article, you will learn about schema design and validation in Zod and how to run it in a TypeScript codebase at...
Read more >
Zod Schema Validation - VeeValidate
The toFormValidator function accepts a Zod object schema and prepares it to be consumed by the vee-validate validation logic. You can pass the...
Read more >
TypeScript schema validation with Zod - Iskander Samatov
Let's start off with the simplest example - primitives. Zod makes it extremely easy to create simple schemas to validate primitives. Let's see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found