Omit<Product, "id"> has every property of Product except id. It is the natural type for data before the server or the database adds fields: a draft passed to create(), which returns the full Product.
Passing the omitted property in an object literal is TS2353, as the first example shows, so callers cannot set an id that create() will overwrite. TypeScript added Omit in version 3.5.
At a glance
| JSDoc in a .js file | TypeScript in a .ts file |
|---|---|
/** @type {Omit<Product, "id">} */ | : Omit<Product, "id"> |
Examples
/** @typedef {{ id: string, sku: string, price: number }} Product */
let nextId = 1;
/**
* @param {Omit<Product, "id">} draft
* @returns {Product}
*/
export function create(draft) {
return { id: `p_${nextId++}`, ...draft };
}
create({ sku: "TEE-01", price: 19.5 });
create({ id: "p_9", sku: "MUG-07", price: 12 });error TS2353: Object literal may only specify known properties, and 'id' does not exist in type 'Omit<Product, "id">'.type Product = { id: string; sku: string; price: number };
let nextId = 1;
export function create(draft: Omit<Product, "id">): Product {
return { id: `p_${nextId++}`, ...draft };
}
create({ sku: "TEE-01", price: 19.5 });
create({ id: "p_9", sku: "MUG-07", price: 12 });error TS2353: Object literal may only specify known properties, and 'id' does not exist in type 'Omit<Product, "id">'.jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} /** @typedef {{ id: string, sku: string, price: number }} Product */
// No error: Omit accepts any key, so the typo removes nothing.
/** @typedef {Omit<Product, "iid">} Draft */
/** @type {Draft} */
const draft = { id: "p_1", sku: "TEE-01", price: 19.5 };
export { draft };jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": ["*.js"]
} The keys are not checked
Omit accepts any key, not only keys of the type, so Omit<Product, "iid"> is not an error. It simply removes nothing, as the second example shows. When the key list matters, use Pick with the keys to keep, or a typedef whose key parameter is constrained (@template T, @template {keyof T} K, @typedef {Omit<T, K>} StrictOmit), which rejects a misspelled key with TS2344.
Gotchas
Omiton a union does not distribute:Omit<A | B, "id">keeps only the properties A and B share. Write a conditional type to omit from each member separately.- The result is a new object type, so hovers show the expanded property list rather than the original name.
Questions
How do I remove a property from a type in JSDoc?
/** @typedef {Omit<Product, "id" | "createdAt">} ProductDraft */.
Sources
- Utility Types: Omit<Type, Keys> · TypeScript handbook
- TypeScript 3.5: the Omit helper type · TypeScript release notes
Last reviewed 20 October 2026.