declare global {
interface Todo extends TimeStampModel {
id: string;
content: string;
order: number;
done: boolean;
userId?: string;
groupId?: string;
}
}
type TodoCreateInterface = Pick<Todo, 'content'>;
The Pick utility type in TypeScript is used to create a new type by selecting only a subset of properties from an existing type. In this case, TodoCreateInterface is defined as a new type that includes only the content property from the Todo type.
interface Todo {
id: string;
content: string;
order: number;
done: boolean;
userId?: string;
groupId?: string;
}
type TodoCreateInterface = Omit<Todo, 'content'>;
const newTodo: TodoCreateInterface = {
id: '1',
order: 1,
done: false,
userId: 'user1',
groupId: 'group1',
};
In this example, the Omit utility type is used to create a new type called TodoCreateInterface that has all the properties of the Todo interface except for the content property.