Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 512 Bytes

README.md

File metadata and controls

23 lines (17 loc) · 512 Bytes

OptionalKeys<Type> constructs a union type by picking all optional properties of object type Type

interface StudentWithOptionalName {
  homework: string | undefined;
  name?: string;
  score: number;
}

type PropertiesThatStudentDoesNotUsuallyHave = OptionalKeys<StudentWithOptionalName>;
//   ^? 'name'

It means we can either set a new value or delete it

declare const user: StudentWithOptionalName;

user.name = "Alex";
delete user.name;

TS Playground – https://tsplay.dev/Wo8ePw