Avatar ·

How to extract a property type from a TypeScript interface?

Hi everyone! I'm new to TypeScript and ran into a problem that I can't solve for several hours. I have an interface describing a user: ```typescript interface User { id: number; name: string; email: string; role: 'admin' | 'user' | 'guest'; createdAt: Date; } ``` Now I need to create a separate type that corresponds only to the `role` property from this interface. That is, I want to get the type `'admin' | 'user' | 'guest'` without having to manually redeclare it. I tried writing something like `type RoleType = User['role']`, but I'm not sure if this is the correct syntax and if it's even possible in TypeScript. I tried googling but found many complex examples with conditional types and mapped types that I don't understand yet. Please advise