xxxxxxxxxx
Required<Type>
Constructs a type consisting of all properties of Type set to required. The opposite of Partial.
interface Props {
a?: number;
b?: string;
}
const obj: Props = { a: 5 };
const obj2: Required<Props> = { a: 5 };
//Property 'b' is missing in type '{ a: number; }' but required in type 'Required<Props>'.
xxxxxxxxxx
// Partial is a utility type that make all the properties of a type optional
interface User {
name: string;
age: number;
}
const updateUserField = (id: number, fieldsToUpdate: Partial<User>) => {
return db.update(id, fieldsToUpdate);
};
// No error, age is not required because of Partial<User>
updateUserField(1, { firstname: 'Chris' });