Partial<>
Type(important) Partial type makes all fields optional on a type. If you have an identical type that requires any of the fields, two types will not be equal to each other in regards to required field
Constructs a type with all properties of passed type set to optional
subset
of the passed typeUsing partial
will fulfill the type expectation with select fields (hence, the subset)
interface Todo { title: string; description: string; } function updateTodo(todo: Todo, fieldsToUpdate: Partial<Todo>) { return { ...todo, ...fieldsToUpdate }; } // full definition const fullTodo = { title: "organize desk", description: "clear clutter", }; // partial definition, leaving out `title` property const partialTodo = updateTodo(todo1, { description: "throw out trash", });
unknown
data typeWhen using a partial, you need a ?
on an optional field that is not required in implementation
partialTypedData?.optionalField