This content originally appeared on DEV Community and was authored by es404020
Partial
Constructs a type with all properties of Type set to optional. This utility will return a type that represents all subsets of a given type.
example
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",
})
Released:
2.1
Reference :Typescript official docs
This content originally appeared on DEV Community and was authored by es404020
es404020 | Sciencx (2021-09-08T07:14:05+00:00) Typescript Utility Partial. Retrieved from https://www.scien.cx/2021/09/08/typescript-utility-partial/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.