Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Last active August 5, 2022 13:57
Show Gist options
  • Save erkobridee/fe081027b006674872e3bcaf4078df75 to your computer and use it in GitHub Desktop.
Save erkobridee/fe081027b006674872e3bcaf4078df75 to your computer and use it in GitHub Desktop.
simple example of how re-shape an object definition in typescript
/*
example of how to re-shape an object definition redefined the required and optional attributes
using the utilities types
https://www.typescriptlang.org/docs/handbook/utility-types.html
*/
interface IPerson {
id: string;
name: string;
age: number;
nationality: string;
}
type IPersonRequiredFields = Required<Pick<IPerson, 'id' | 'name'>> & Partial<Omit<IPerson, 'id' | 'name'>>;
const me: IPersonRequiredFields = {
id: "123",
name: "It's Me Mario",
age: 30
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment