Bug: Inconsistent "Expected never, received array" in v2
See original GitHub issueEnvironment:
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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Awesome, thanks for the great work @colinhacks
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.