Current section: SQL 6 exercises

Handling TypeScript Errors and Runtime Type Checking with Prisma and Zod


00:00 So what are we going to do about these TypeScript errors? The problem is that data.users is not available on here. The reason it's not available is because this is going to be unknown. We don't know what's going to come back from this Prisma query raw.

00:18 There are query builders that you can use other tools to interact with your database that could definitely perform this type of a query and make it type safe. But there are a lot of trade-offs associated with using those tools, and I just really, really like Prisma's trade-offs.

00:34 This is one situation where Prisma doesn't really necessarily shine. Eventually, I think it's very possible that they could implement something like that. But yeah, it's not my favorite part about Prisma. But to be frank, we don't really do a lot of raw queries like this when we're using

00:54 Prisma anyway. And so I'm actually fine with the way that this is currently set up. It's not my favorite, and it would be cool if it were more type safe, but the fact is it's not. And so we're going to make it type safe with some runtime type checking. So that's what you're going to be doing in this exercise.

01:13 You have Zod to do some runtime type checking for us. And yeah, we'll talk a little bit more about why you might want to do that when I go through the solution. Give that a shot, and we will see you when you're done.