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.

Bug: Inconsistent "Expected never, received array" in v2

See original GitHub issue

Environment:

Node 12.18.2 Webpack 4.44.2 Zod 2.0.0-beta.21

// tsconfig.json
// target: commonjs2
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2019",
    "lib": ["es2020"],
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false,
    "typeRoots": ["./node_modules/@types", "./typings"]
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.test.ts", "**/*.it.ts"]
}

Error

I’m experiencing the following error when the parser encounters an unknown field: Expected never, received array.

The weirdest thing is that this does not happen in local development, but it only happens when files are bundle with webpack and production mode.

Expected result

According to v2 doc: By default Zod object schema strip unknown keys from the output.

Code

Here’s a snippet of code that I have:

const atAgencySchema = z
  .object({
    agencyId: z.string(),
    market: z.enum(['X', 'Y', 'Z']),
    name: z.string(),
  })

// ...
const record = { agencyId: 'id', market: 'Y', name: 'yo', skills: ['1'] } 
atAgenciesSchema.parse(record) // throws "Expected never, received array"

Workaround

Reverted back to v1, and used nonstrict()

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mmeylancommented, Nov 18, 2020

Awesome, thanks for the great work @colinhacks

1reaction
colinhackscommented, Nov 18, 2020

Okay I’ve identified the problem! Very silly mistake on my part in the parsing logic. Fixed in beta 22. Thanks for the great repro @mmeylan.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent behavior when passing array schema to a property
Describe the bug There's an inconsistency that leads to some unexpected behavior when using nested schemas. The problem is best described by ...
Read more >
Numpy.dot bug? Inconsistent NaN behavior - Stack Overflow
BLAS seems to have expected behaviour when the first operand has a NaN, and the wrong when the first operand is zero and...
Read more >
Why do I get the error “Dimensions of arrays being ...
This error is encountered when you try to vertically concatenate arrays that do not have compatible sizes. · C is a matrix with...
Read more >
expected - got CHAR, Detail view bind variables — oracle-tech
prepareRowSetForQuery() solved the problem for me. The Array bind variable was null and that was the reason for inconsistent datatype error.
Read more >
Inconsistent Typename Error - Relay
The most common reason for this error is that 2 objects backed by an ID are using the plain ID as the id...
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