Partial<T> Partial (with Required)
Last updated: 2026-10-22
Partial<T> Partial (with Required)
Partial<T> makes every property of T optional: perfect for "partial updates" (form drafts, patch endpoints) — no need to hand-write a new type just to change two fields. It is the mirror of Required<T>.
| Group | Utility Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
type Partial<T> = {
[K in keyof T]?: T[K];
};
// Usage
function applyPatch(user: UserProfile, patch: Partial<UserProfile>): UserProfile;
⚙️ Parameters
| T | The object type to transform; each property K and its type T[K] are traversed by the mapped type |
|---|
Returns:A new type with the same properties as T, but all optional (?).
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
{"id":1,"name":"Diana","email":"d@example.com","age":22}
(Runtime output after transpilation; the patch only passes age, other fields keep their values)
💡 Notes
ℹ️ Info Implementation is a mapped type: [K in keyof T]?: T[K] — traverse every key of T and add the ? marker (lesson 19 "utility type implementations" derives it fully).
⚠️ Note Partial is shallow: nested object property types do not become optional recursively; write your own DeepPartial (recursive mapped type) for deep optionality.
💡 Tip Partial mirrors Required (adding vs removing ?); combine with Pick/Omit for precise patch types that only allow changing specific fields.
🏷️ Related Utility Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q Partial vs hand-writing ? on every property?
A Same effect, but Partial tracks the source type automatically: add a field to UserProfile and Partial<UserProfile> picks it up; a hand-written copy silently drifts.
Q Are nested properties made optional too?
A No. Partial is shallow — only top-level properties get ?; address: {city: string} as a whole becomes optional, but city inside stays required. Write DeepPartial for deep needs.
Q Can I assign undefined to fields after Partial?
A Omitting fields is always allowed; explicitly assigning undefined depends on strictNullChecks: under strict mode Partial fields are T[K] | undefined. Keep strict mode on.