Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Last active September 26, 2025 07:19
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
/*
Useful references:
https://www.typescriptlang.org/docs/handbook/utility-types.html
https://github.com/piotrwitek/utility-types
*/
export type Optional<T extends object, K extends keyof T = keyof T> = Omit<
T,
K
> &
Partial<Pick<T, K>>;
/*
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