Video details

Type-Safety Beyond TypeScript - Joël Galeran @ Prisma Day 2020


Joël Galeran

The talk was streamed on #PrismaDay​ | June 26th, 2020
Prisma Day is a community-focused online conference on modern application development and databases.​
Subtitles for this video have been professionally transcribed. Prisma can provide the subtitles for your tech video as well - get in touch with us at [email protected]


- Welcome to my lightning talk. Let's see what's about Type-Safety Beyond TypeScript. And I'm Joel. I live in Berlin. And I'm a TypeScript developer at Prisma. And there are two kinds of types of type-safety. The well-known one, especially in the TypeScript world is the compile time type-safety. And it's really nice. But we'll see that in some cases, runtime type-safety will be extremely beneficial. And let's say for example when you import data, and I prepared a live demonstration about that. So let's go to VS Code. And here I put some data in a JSON file, but let's say this is an API from a server, from a third party server. And well basically it's typed as any. You could type it a little bit, but yeah. So here we can see an example of compile time type-safety, for example like the typo, because if I run it, I will have the same error. And it will tell me that storytext doesn't exist, and will probably be with an underscore here because I prepared the schema already, and I did it as the data. And let's take a quick look at the data. So the data is here. It looks right like the schema, but maybe the data is corrupted and you don't know before you import it. And let's try import it. So I prepared this in TypeScript. But to really show the compile time problem, let's switch to JavaScript because here we only in runtime type-safety, we forget about compile time. TypeScript is nice for that. But when you only have JavaScript, you still want data safety. And let's run this example. So here, okay. So it looks like we have a problem. So I'm gonna look around. Here it looks like we have two problems actually. And the Prisma Client creates this really nice error, and explains what's happening. So here the first problem is that the object ID should be an integer. And we parse the string. So I can parse it as an integer, and this will solve it. And we also have the problem of storytext argument that is wrong. So let's fix both. Well this one is fixed. And let's do a parseInt, and rerun it again. So it looks like it worked. But it looks like at runtime validation, Prisma Client found that the created_at value from this API, the date/time is not correct. So looking at it, it looks like those calls in this date/time that is probably not correct. So here I have access to the data, so I can fix it. But yeah I mean it was to fix it if you don't have access to the data. For here, let's do the simple way. So there's one more runtime validation. Let's run it again. And here we also have again one more time author 1337. And so that means let's run it again. And an easy way here will be to, it's always the string. Rerun it again. Now it worked. So you can see that runtime validation is really important when importing data here for example, because it really helps bringing confidence in your code. Thank you for your attention.