Skip to content

Instantly share code, notes, and snippets.

@tamert
Last active September 12, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamert/8b46327bbb4ef5a659bffed9f1f5ca2c to your computer and use it in GitHub Desktop.
Save tamert/8b46327bbb4ef5a659bffed9f1f5ca2c to your computer and use it in GitHub Desktop.
Omit
interface Book {
id: number;
title: string;
subject?: 'crime' | 'comedy';
body: string;
}
type BookPreview = Omit<Book, "id" | "body">;
const book: BookPreview = {
title: "Arsène Lupin, Gentleman Burglar",
subject: 'comedy',
};
console.log(book)
/**
* {
"title": "Arsène Lupin, Gentleman Burglar",
"subject": "comedy"
}
*/
const newBook: BookPreview = {
title: "The Hobbit",
};
console.log(newBook)
/**
* {
"title": "The Hobbit"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment