TypeScript example

How to omit a property from a type in TypeScript

8 min read Updated Nov 2026 Runs in an isolated runtime
Quick answer

Use the built-in Omit utility type: type PublicUser = Omit<User, "password">; is User without password. Pass a union to drop several keys: Omit<User, "password" | "email">. Omit only changes the type; to remove the property from an actual object, destructure it away: const { password, ...rest } = user;

TypeScript ships a set of utility types that build a new object type from an existing one, so you never copy an interface by hand to leave out one field. Omit drops keys, Pick keeps them, Partial makes every property optional, and Required makes every property required. Combined, they also make a single property optional. The sections below cover each one, the errors the checker gives once a property is gone, and the gotcha that trips most people: none of this removes anything from the object at runtime. Each example runs on this page: hit Run, then edit the code and run it again.

1Omit<T, K>: the type without some keysRecommended

Omit<T, K> takes an object type and the keys to leave out, as a string literal or a union of them, and gives back a type with every other property unchanged: optional stays optional, readonly stays readonly. It has been built in since TypeScript 3.5. The type is only half the job when the data really must not carry the property, say a password on its way to a client, so the function below also removes it from the object with rest destructuring: password gets its own variable and rest holds everything else, which TypeScript types as exactly Omit<User, "password">.

omit.ts
interface User {
    id: number;
    name: string;
    email: string;
    password: string;
}

// Same properties as User, minus password
type PublicUser = Omit<User, "password">;

// Several keys at once: pass a union
type UserCard = Omit<User, "password" | "email">;

function toPublic(user: User): PublicUser {
    // Rest destructuring drops the property from the actual object
    const { password, ...rest } = user;
    return rest;
}

const ada: User = { id: 1, name: "Ada", email: "[email protected]", password: "s3cret" };

const pub = toPublic(ada);
console.log(pub);
console.log(Object.keys(pub).join(", "));

const card: UserCard = { id: ada.id, name: ada.name };
console.log(card);

Output

The public user prints { id: 1, name: 'Ada', email: '[email protected]' } and its keys are id, name, email: the password is gone from the object as well as the type. The card type drops two keys and prints { id: 1, name: 'Ada' }. If your linter flags the unused password variable, rename it to _password (const { password: _password, ...rest } = user) or configure the rule to ignore rest siblings.

2What the checker rejects once a property is omitted

Types vanish when the code runs, so the proof that password is gone from PublicUser is the compiler refusing to use it. This embed fails on purpose: it reads the omitted property and writes an object literal that still has it, and the type errors stop the run before anything executes.

omit-errors.ts
interface User {
    id: number;
    name: string;
    password: string;
}

type PublicUser = Omit<User, "password">;

function greet(user: PublicUser): string {
    // password is not part of PublicUser any more
    return `${user.name} (${user.password})`;
}

// An object literal may not carry the omitted property either
const pub: PublicUser = { id: 1, name: "Ada", password: "s3cret" };

console.log(greet(pub));

Output

Reading the property gives error TS2339: Property 'password' does not exist on type 'PublicUser'. The literal gives error TS2353: Object literal may only specify known properties, and 'password' does not exist in type 'PublicUser'. Delete (${user.password}) and the password property from the literal, and it runs. The second error is the excess property check, and it only fires on object literals; the next section shows what that lets through.

3Omit does not remove the property at runtime

TypeScript types are structural: a value fits a type when it has at least the properties the type asks for. A full User has everything PublicUser needs, so assigning a User variable to a PublicUser compiles with no error, and the password travels along. Annotating a variable or a return type with an Omit type is a promise about what you may read, not a filter. Only code that builds a new object, such as rest destructuring or listing the properties you keep, removes the data.

runtime-leak.ts
interface User {
    id: number;
    name: string;
    password: string;
}

type PublicUser = Omit<User, "password">;

const ada: User = { id: 1, name: "Ada", password: "s3cret" };

// Compiles: a User has every property PublicUser needs, extras are allowed
const leaked: PublicUser = ada;
console.log(JSON.stringify(leaked));
console.log("password" in leaked);

// Copy only what the type promises: destructure the property away
const { password, ...safe } = ada;
const clean: PublicUser = safe;
console.log(JSON.stringify(clean));
console.log("password" in clean);

Output

The annotated variable still serializes as {"id":1,"name":"Ada","password":"s3cret"} and "password" in leaked is true; the destructured copy prints {"id":1,"name":"Ada"} and false. The same goes for JSON.stringify in an API handler and for spreading the object into another one. To strip a key you only know as a variable, copy the object and delete the key from the copy, or rebuild it with Object.fromEntries and a filter.

4Pick, Exclude and a key-checked Omit

Pick<T, K> is the opposite of Omit: it keeps only the keys you list, which reads better when you want two fields out of twenty. Exclude<U, M> is a different tool that people often reach for first: it removes members from a union of values, such as one role out of "admin" | "editor" | "viewer", and does nothing useful to an object type. The two combine into Omit itself: Pick<T, Exclude<keyof T, K>> keeps every key except K. Written with K extends keyof T, that becomes an Omit that rejects keys the type doesn't have; the built-in one accepts any string.

pick-exclude.ts
interface User {
    id: number;
    name: string;
    email: string;
    password: string;
}

// Pick keeps the keys you list, Omit drops them
type Contact = Pick<User, "name" | "email">;

// Exclude works on unions of values, not on object types
type Role = "admin" | "editor" | "viewer";
type StaffRole = Exclude<Role, "viewer">;

// Omit<T, K> accepts any key, even a typo. This one only accepts keys of T.
type StrictOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type Safe = StrictOmit<User, "password">;

const contact: Contact = { name: "Ada", email: "[email protected]" };
const roles: StaffRole[] = ["admin", "editor"];
const safe: Safe = { id: 1, name: "Ada", email: "[email protected]" };

console.log(contact);
console.log(roles);
console.log(Object.keys(safe));

Output

It prints the picked { name: 'Ada', email: '[email protected]' }, the roles [ 'admin', 'editor' ] and the keys [ 'id', 'name', 'email' ]. Misspell the key as "pasword" and StrictOmit fails right on the type with error TS2344: Type '"pasword"' does not satisfy the constraint 'keyof User'. The built-in Omit<User, "pasword"> compiles, removes nothing, and the mistake only shows up where an object misses the property; for type Loose = Omit<User, "pasword"> that is error TS2741: Property 'password' is missing in type '{ id: number; name: string; }' but required in type 'Loose'.

5Partial<T>: make every property optional

Partial<T> adds ? to every property of T, the usual type for an update or a set of overrides: the caller passes only what changes, and a spread merges it over the defaults. Its counterpart Required<T> removes every ?. An optional property may be missing, so its type includes undefined, and the function below checks before doing arithmetic with it.

partial.ts
interface Settings {
    theme: "light" | "dark";
    fontSize: number;
    autosave: boolean;
}

const defaults: Settings = { theme: "light", fontSize: 14, autosave: true };

// Partial<Settings>: every property becomes optional
function withChanges(base: Settings, changes: Partial<Settings>): Settings {
    return { ...base, ...changes };
}

console.log(withChanges(defaults, { theme: "dark" }));
console.log(withChanges(defaults, {}));

// A property of a Partial may be missing: check before using it
function describe(changes: Partial<Settings>): string {
    if (changes.fontSize !== undefined) {
        return `font size -> ${changes.fontSize + 2}px`;
    }
    return "font size unchanged";
}

console.log(describe({ fontSize: 16 }));
console.log(describe({ autosave: false }));

// Required<T> does the opposite: every property must be present
const full: Required<Partial<Settings>> = { theme: "dark", fontSize: 12, autosave: false };
console.log(Object.keys(full).length);

Output

The merges print { theme: 'dark', fontSize: 14, autosave: true } and the unchanged defaults, then font size -> 18px and font size unchanged, and the Required object has 3 keys. Drop the !== undefined check and this page's compiler, which runs without strict, accepts changes.fontSize + 2. With strictNullChecks on, as in most projects, it fails with error TS18048: 'changes.fontSize' is possibly 'undefined'. For more ways to handle that, see check for null or undefined. One trap with spreads: { theme: undefined } is a valid Partial and overwrites the default with undefined.

6Make a single property optional

There is no built-in for "this type, but with id optional". Build it from the pieces above: Omit the keys, then intersect with a Partial of just those keys. PartialBy<T, K> below is the helper most codebases end up writing, and swapping Partial for Required gives the reverse, RequiredBy<T, K>. A typical use is the input of a create function, where the caller may leave out the fields the function fills in.

one-optional.ts
interface Post {
    id: number;
    title: string;
    body: string;
    createdAt: string;
}

// Make only the keys K optional, keep the rest as they are
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

// The opposite: make only the keys K required
type RequiredBy<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;

// The caller may leave out id and createdAt; the function fills them in
type NewPost = PartialBy<Post, "id" | "createdAt">;

let nextId = 1;

function savePost(input: NewPost): Post {
    return {
        ...input,
        id: input.id ?? nextId++,
        createdAt: input.createdAt ?? "2026-11-19",
    };
}

console.log(savePost({ title: "Hello", body: "First post" }));
console.log(savePost({ id: 42, title: "Draft", body: "...", createdAt: "2026-01-01" }));

interface Options {
    url?: string;
    retries?: number;
}

const opts: RequiredBy<Options, "url"> = { url: "/api/users" };
console.log(opts.url, opts.retries);

Output

The first post gets the generated fields, { title: 'Hello', body: 'First post', id: 1, createdAt: '2026-11-19' }, and the second keeps its own id: 42. The options line prints /api/users undefined: url is now required, retries stays optional. The helper's result is an intersection of two object types, which behaves like one flat object type. To add properties or override one's type instead, see extend a type.

7Which should you use?

MethodWhat you getBest for
Omit<T, "a" | "b">T without a and bDropping a few keys: the default
const { a, ...rest } = objA new object without aRemoving the data, not just the type
Pick<T, "a" | "b">Only a and bKeeping a few keys of a big type
Exclude<Union, "x">The union without xUnions of values, not object types
Partial<T> / Required<T>Every property optional / requiredUpdates, overrides, options
Omit<T, K> & Partial<Pick<T, K>>Only K optionalCreate inputs with generated fields

Frequently asked questions

What is the difference between Omit and Exclude in TypeScript?

Omit<T, K> works on an object type and removes properties: Omit<User, "password"> is User without its password key. Exclude<U, M> works on a union and removes members: Exclude<"admin" | "editor" | "viewer", "viewer"> is "admin" | "editor". Omit is built from the two others: Pick<T, Exclude<keyof T, K>>.

Why does Omit not complain about a key that does not exist?

The built-in Omit<T, K extends keyof any> accepts any string, number or symbol as the key, so Omit<User, "pasword"> compiles and removes nothing. Declare your own with a constraint, type StrictOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>, and a typo fails with error TS2344: Type '"pasword"' does not satisfy the constraint 'keyof User'.

Why does Omit on a union type lose properties?

Omit maps over keyof T, and the keys of a union are only the keys all members share. So Omit<Circle | Square, "id"> keeps kind but drops radius and side, and { kind: "circle", radius: 2 } fails with error TS2353: Object literal may only specify known properties, and 'radius' does not exist in type 'NewShape'. Apply it to each member with a conditional type: type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;, which keeps the union and its narrowing on kind.

How do I change the type of one property instead of removing it?

Omit it and add it back with the new type: interface Admin extends Omit<User, "role"> { role: "admin" }, or type Admin = Omit<User, "role"> & { role: "admin" }. Extending User directly with an incompatible type fails with error TS2430: Interface 'Bad' incorrectly extends interface 'User'. The extend-a-type example covers extends and intersections in depth.

How do I make nested properties optional too?

Partial is shallow: it makes the top-level properties optional but leaves the objects inside them as they are. A recursive mapped type goes all the way down: type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] };. With it, { server: { port: 8080 } } is a valid DeepPartial<Config> even though server also has a required host.

Can I use Omit with an interface or a class?

Yes. Omit, Pick and Partial take any object type: an interface, a type alias, or a class used as a type (its public instance properties and methods). The result is a type alias, but an interface can extend it, as in interface Draft extends Omit<Post, "id"> {}. Omitting a method from a class type works the same as omitting a field.

Run it yourself

Open any of these in the full TypeScript editor to tweak, run and share.

TypeScript playground