Friday, December 02, 2022

TypeScript partial interface: optional | required

 Make the TypeScript interface partially optional/required | pawelgrzybek.com

interface Dude {
  name: string;
  age: number;
}

type DudeAllOptional = Partial<Dude>;

// name and age are optional
const dan: DudeAllOptional = {};
interface Dude {
  name: string;
  age?: number;
}

type DudeAllRequired = Required<Dude>; // all required

etc...


No comments: