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.
| 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 Omit<T, K extends string | number | symbol> =
Pick<T, Exclude<keyof T, K>>;
// Usage
type PublicAccount = Omit<Account, "passwordHash" | "twoFA">;
⚙️ Parameters
| T | The source object type whose properties are dropped |
|---|---|
| K | The 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.
🏷️ Related Utility Types
💡 Related cases
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.