Use the Omit helper type to drop properties from a type
TypeScript 3.5 introduced an Omit
helper, which allows you to exclude specific properties from an existing type. One situation where this is useful is excluding internal stuff from auto-generated types, e.g.:
// Imagine this is provided from outside:
interface InternalBook {
_intenralId: number;
id: string;
name: string;
}
// Now we can just drop the internal stuff, while preserving type safety:
type Book = Omit<InternalBook, "_intenralId">;
// Let's test it:
const book: Book = {
id: "1",
name: "Life of Pi"
};
More information can be found here.