Errors 10 exercises
Problem

Fixing "X Is Not Assignable To Y"

In this exercise, we are looking at a user object and a UserProfile interface in TypeScript.


interface UserProfile {
id: string;
preferences: {
theme: "light" | "dark";
};
}
let user: UserProfile = {
id: "123",
preferences: {
theme: "blue",

Loading exercise

Transcript

00:00 In this exercise we have a user object and we have an interface user profile. We are then assigning the annotating user with the user profile type and passing it some stuff. But we're getting an error down the bottom here. This error is saying type blue is not assignable to type light or dark.

00:19 Your job is to work out why this error could be happening and what kind of ways we could potentially fix this. I thought of three potential solutions to this. Good luck.