Omit<T, K>

Last updated: 2026-10-22

Omit<T, K> Omit

Omit<T, K> drops the properties named by K from T and keeps the rest as a new type. Typical uses: sanitizing (removing passwordHash) or turning a database row into an API response. It is the mirror of Pick — when you only need to drop a few fields, Omit wins.

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 Omit<T, K extends string | number | symbol> =
  Pick<T, Exclude<keyof T, K>>;

// Usage
type PublicAccount = Omit<Account, "passwordHash" | "twoFA">;

⚙️ Parameters

TThe source object type whose properties are dropped
KThe union of keys to drop; note K is not required to be a key of T — a misspelled key is silently ignored

Returns:A new type containing every property of T except those named by K, with identical types.

▶ Example

Edit the code below and click Try it to see the transpiled result:

Output:

{"username":"carol","email":"carol@example.com"}

(Runtime output after transpilation; the implementation strips sensitive fields via destructuring rest, and PublicAccount no longer has passwordHash at the type level — a typo like Omit<Account, "passwordHash2"> would leave the sensitive field in)

💡 Notes

ℹ️ Info The implementation is a combo: Omit<T, K> = Pick<T, Exclude<keyof T, K>> — first Exclude drops K from the key union, then Pick keeps the rest.
⚠️ Note K is not validated against T's keys: Omit<Account, "passwordHashh"> (one extra letter) compiles and keeps the sensitive field. For security-sensitive sanitization prefer a strict variant: type StrictOmit<T, K extends keyof T> = Omit<T, K>.
💡 Tip Omit is a blacklist: fields added to Account later appear in the Omit result automatically. That is exactly why it suits "expose everything, hide a few" scenarios.
More cases coming soon.

📚 Related tutorials

❓ FAQ

Q Which should I choose, Omit or Pick?
A Go by intent: "I need exactly these" → Pick (whitelist, clearest for few fields); "drop these" → Omit (blacklist, future source fields flow through). For security-sensitive sanitization Pick is safer (unknown keys error out).
Q Why does Omit not validate keys like Pick does?
A The official K extends string | number | symbol constraint is deliberately loose to support omitting from shapes that are not fully known. The looseness cuts both ways: flexible, but a typo fails silently. A one-line custom StrictOmit restores strictness.
Q How do I actually remove a property at runtime?
A Omit only changes types. At runtime use destructuring rest: const { passwordHash, ...rest } = account; or delete account.passwordHash (a compile error on required properties under strict TS). Destructuring rest is the recommended approach.
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%

🙏 帮我们做得更好

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

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