Write isUser(value): a type guard that checks parsed JSON really is a User.
isUser takes an unknown value and returns true only for an object with a number id, a string name, and, if it has an email, a string email. After if (isUser(data)), TypeScript should treat data as a User.
type User = { id: number; name: string; email?: string }; function isUser(value) { // your code} // const data: unknown = JSON.parse(text);// if (isUser(data)) console.log(data.name); // data is a User hereThe answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…