Middle
interface User { id: number; name: string; email: string; role: "admin" | "user"; settings: { theme: "dark" | "light"; notifications: boolean; }; } type CreateUser = Omit<User, 'id'> type UpdateUser =
sobes.tech AI
Answer from AI
To define the UpdateUser type, which represents updating a user, it is common to make all fields optional except for id, so that any properties except the identifier can be changed. In TypeScript, this can be achieved using Partial and Pick or Omit.
Example:
interface User {
id: number;
name: string;
email: string;
role: "admin" | "user";
settings: {
theme: "dark" | "light";
notifications: boolean;
};
}
type CreateUser = Omit<User, 'id'>
type UpdateUser = Partial<Omit<User, 'id'>> & { id: number };
Here, UpdateUser requires the id field for user identification, while the other fields are optional, which is convenient for partial data updates.