Registry / testing / myzod
library1.12.1jsnpmunverified

myzod (v1.12.1) is a TypeScript-first schema validation library with type inference, inspired by Zod. It provides a familiar API for defining schemas using object, string, number, boolean, array, record, union, intersection, and more. Key differentiators include significantly faster parsing performance (claimed ~25x faster than Zod in benchmarks) and a focus on type safety with strict validation. The library emits TypeScript type declarations and supports ESM and CJS. It is actively maintained on GitHub with periodic releases, though less frequent than more popular alternatives like Zod. Its type system closely mirrors TypeScript's own, allowing complex generics like Pick, Omit, and Partial.

npm install myzod
INSTALL
IMPORT
SIG · MYZOD
M
myzod
testingjavascriptv1.12.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

myzod
import myzod from 'myzod'
const myzod = require('myzod')
Default import is the recommended way. CommonJS require also works but may lack type inference benefits in TypeScript.
Infer
import { Infer } from 'myzod'
import Infer from 'myzod'
Infer is a named export used to extract the TypeScript type from a schema. Must be imported as a named import.
Type
import { Type } from 'myzod'
Type is the base class for all schemas. Typically not imported directly but available if needed for generic constraints.
ValidationError
import { ValidationError } from 'myzod'
import myzod, { ValidationError } from 'myzod'
ValidationError is a named export. It is thrown by parse() and returned by try().

Defines a User schema with string patterns, number constraints, optional fields, and nullable arrays, then parses an input object with type inference.

import myzod, { Infer } from 'myzod'; const userSchema = myzod.object({ id: myzod.number(), name: myzod.string().min(1).pattern(/^[A-Z][a-z]+$/), email: myzod.string().pattern(/^[^@]+@[^@]+$/), age: myzod.number().min(0).max(120).optional(), roles: myzod.array(myzod.string()).nullable() }); type User = Infer<typeof userSchema>; const input: unknown = { id: 1, name: 'Alice', email: 'alice@example.com', age: 30, roles: ['admin', 'user'] }; try { const user: User = userSchema.parse(input); console.log(user); } catch (err) { if (err instanceof myzod.ValidationError) { console.error(err.message); } }
Debug
Known issues
breakingSchema type inference changed: `Infer` may produce different types compared to v0.x due to stricter validation.
fix
Review inferred types when upgrading from v0.x. Use `Infer<typeof schema>` to get new types.
affects: >=1.0.0
deprecatedUse of `myzod.object()` with duplicate keys is not allowed and will throw a ValidationError.
fix
Remove duplicate keys from object schema definitions.
affects: >=1.0.0
gotchaNull handling: `.nullable()` is separate from `.optional()`. A nullable optional field must have both modifiers, e.g., `.optional().nullable()`.
fix
Chain both `.optional()` and `.nullable()` when needed.
affects: >=1.0.0
gotchaString patterns use JavaScript RegExp, not global flags. `pattern(/^[A-Z]/)` is correct; passing flags like 'g' may have unintended behavior.
fix
Use regex without global or sticky flags.
affects: >=1.0.0
deprecated`myzod.lazy()` requires a function that returns a schema. Breaking change if you passed a schema directly before v1.5.
fix
Wrap lazy schema in a function: `myzod.lazy(() => mySchema)`
affects: >=1.5.0
Errors
Common errors & fixes
TypeError: myzod is not a function
Importing myzod incorrectly (e.g., `import { myzod } from 'myzod'` instead of default import).
fix
Use default import: `import myzod from 'myzod'`
ValidationError: expected number at path "age"
Value at 'age' is missing or not a number, but schema requires number.
fix
Ensure value matches schema type, or make field optional/nullable.
TypeScript: Type 'unknown' is not assignable to type 'Infer<typeof schema>'
Using `Infer` on a schema that is not fully defined or is recursive.
fix
Define the schema as a type or use `satisfies` keyword if available.
ValidationError: expected value to match pattern /^[A-Z]/
String value does not satisfy the pattern regex.
fix
Adjust the input string to match the pattern or modify the schema pattern.
Upgrade
Version history
1.12.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
packagemyzod
myzod — npm install myzod · libregistry