Update
Since the release of Typescript 3.5, the Omit
type is now included in the standard types provided by Typescript.
Initial response
Prior to version 2.8, you could achieve this by utilizing the Exclude
conditional type along with the Pick
mapped type.
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
interface Numbers {
number: number;
number2: number;
number3: number;
}
const numbers:Omit<Numbers, 'number3'> = {
number: 1,
number2: 2
};
Prior to version 2.8, the definition of Omit
would look like this:
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;