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>.

GroupUtility Types
KindType
Strict modeNot 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

TThe 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.
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏