Branded Types 7 exercises

Using Branded Types as Entity Id’s

Here we have a User and a Post, both represented in interfaces:

interface User {
id: string;
name: string;
interface Post {
id: string;
title: string;
content: string;

There is a db that represents the shape of the database:

const db: { users:

Loading exercise


0:00 In this exercise, we have a user and we have a post, both represented in interfaces. We have an ID of string here on both of them. We have a DB here that's representing the shape of the DB.

0:14 We've got some functions here that say getUserByID, ID string, and getPostByID, ID string. What we're trying to do here is we're trying to restrict these functions so that they only get a user with a user ID and a post with a post ID.

0:30 We have a couple of branded types up here that are already being used in the tests. Your job here is to work out where these branded types should go and what you need to do with them in order to achieve this goal. Good luck.