TypeScript: Documentation - Utility Types (typescriptlang.org)
interface Todo {
title: string;
description: string;
}
function updateTodo(todo: Todo, fieldsToUpdate: Partial<Todo>) {
return { ...todo, ...fieldsToUpdate };
}
const todo1 = {
title: "organize desk",
description: "clear clutter",
};
const todo2 = updateTodo(todo1, {
description: "throw out trash",
});
The partial type allows you to do things like define a set of defaults, accept a partial, and then fill out the values that are provided rather than all of the options
interface Todo {
title: string;
}
const todo: Readonly<Todo> = {
title: "Delete inactive users",
};
todo.title = "Hello"; // This assignment will throw an issue
Allows you to define a type as readonly. This is good for marking things that you don't own as readonly