Open this lesson on a wider screen to play it. The narrated transcript and animated code need room to sit side by side.
← All lessonsinterface User {
id: string;
name: string;
}
// Failure is signalled by throwing — so it vanishes from the type.
function getUser(id: string): User {
if (id === "") throw new Error("missing id");
return { id, name: "Ada" };
}
const user = getUser("1");
// ^? User