QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Omit Keys of Type

Removes keys of a specified type from an object type.

  • helper-types
  • typedefinition
  • omit
  • keys

Install

npx shadcn@latest add https://quicksnip.dev/r/omit-keys-of-type.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

type OmitKeysOfType<T, U> = {
    [K in keyof T as T[K] extends U ? never : K]: T[K];
};

Usage

type A = {
    id: string;
    isActive: boolean;
    data: number[];
};

type WithoutBoolean = OmitKeysOfType<A, boolean>; // { id: string; data: number[] }