JS Built-ins
TypeScriptbeginner

Utility Types β€” Partial<T>

πŸ“– Usage Example
function mergePartial<T extends object>(base: T, patch: Partial<T>): T {
  return { ...base, ...patch }
}
mergePartial({ a: 1, b: 2 }, { b: 99 })   // β†’ { a: 1, b: 99 }

Partial<T> makes all properties optional, enabling partial update patterns without type errors.

Utility Types: Partial<T>

Partial<T> makes every property of T optional.
Useful for update functions where you only want to provide changed fields.

Challenge: Implement mergePartial<T extends object>(base: T, patch: Partial<T>): T that merges a partial update into a base object.

mergePartial({ a: 1, b: 2 }, { b: 99 })  // β†’ { a: 1, b: 99 }
πŸ’‘ Hints (1)
  • β€’ Spread operators: { ...base, ...patch } β€” the patch overwrites base fields.