In the last exercise, you checked the export at the door with a handwritten guard. The guard works, but your code describes a sighting twice. The Sighting type tells the checker which properties to expect, and the guard’s typeof checks test those same properties while the program runs. The checker never compares the two, so when the app’s export gains a property, you have to remember to change both.
In this lesson, you’ll install a schema library, describe a sighting once, and let that one description check the data at runtime and give the checker its type. Start by checking the library itself, because it’s code from outside your project too.
Install Zod and Check It First
A schema is a description of the shape that data should have, written as an ordinary JavaScript value your program can test data against. Libraries that build schemas are common on npm, and this course uses Zod. The idea you’ll learn here works the same way in the others.
Before you install a package, give it the same four checks as any other: the exact name, how widely it’s used, where its source code lives, and when it was last published. In the millbrook-birders folder, ask the registry about Zod without installing anything:
$ npm view zod
[email protected] | MIT | deps: none | versions: 1013
TypeScript-first schema declaration and validation library with static type
inference
https://zod.dev
keywords: typescript, schema, validation, type, inference
dist
.tarball: https://registry.npmjs.org/zod/-/zod-4.6.7.tgz
.shasum: e806cf64a7f4e37635ce9f2f52c04c3766f75e5b
.integrity: sha512-g8W2D2kU6a8untc053fX...
.unpackedSize: 6.1 MB
maintainers:
- colinhacks <[email protected]>
dist-tags:
latest: 4.6.7
canary: 4.5.0-canary.20260828T171753
beta: 4.1.13-beta.0
alpha: 3.25.68-alpha.11
next: 3.25.0-beta.20250519T094321
published a month ago by GitHub Actions <[email protected]>
The first line confirms the name, zod, and the newest version. deps: none means Zod brings no other packages with it, and the last line shows a recent release. Your version and date will be newer if Zod has had a release since this lesson was written. Any 4.x release works for this course. Ask for the repository URL, since the summary leaves it out:
$ npm view zod repository.url
git+https://github.com/colinhacks/zod.git
The repository belongs to colinhacks, the same account that maintains the package. For the weekly downloads, open Zod’s package page on npm. They run to hundreds of millions, and a lookalike package wouldn’t get numbers like that, so this is the Zod that other projects install. If you’d like a refresher on why these checks matter, the RealJS article on npm supply chain attacks tells the story.
Zod passes, so install it:
$ npm install zod
added 1 package, and audited 6 packages in 814ms
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities