Avatar ·

TypeScript: Error "Type 'string' is not assignable to type" when working with objects

Hi! I started learning TypeScript and encountered a strange error. I have an interface describing a user: ```typescript interface User { name: string; age: number; role: 'admin' | 'user'; } ``` I'm trying to create a function that takes a string with a role and returns a user object: ```typescript function createUser(name: string, age: number, role: string): User { return { name, age, role }; } ``` But TypeScript throws an error: "Type 'string' is not assignable to type '"admin" | "user"'" at the `role` location. I don't understand why this happens. After all, `role` is a string, and I'm passing a string that should match the type `'admin' | 'user'`. In JavaScript this would work without issues. I tried explicitly casting the type: `role as 'admin' | 'user'`, but this is