Lesson

Make a Type-safe and Runtime-safe WebSocket Communication with Zod

Ensure runtime and type-safety of a WebSocket communication using Zod.

Access
Included
Transcript
Needs source

As we send and handle more and more WebSocket events, it would be great to bring some type safety to the mix. But type safety along won't cut it. We need the runtime safety as well.

Luckily, zod is to the rescue. In this one, we will use zod to create a chat message schema and use it to create createChangeMessage and parseChatMessage utilities to help us develop and mock our WebSocket API.

Resources