Making optional properties nullable in TypeScript

PHOTO EMBED

Fri Jan 28 2022 20:56:14 GMT+0000 (Coordinated Universal Time)

Saved by @antistructure #typescript #javascript

type RequiredKeys<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K }[keyof T];

type OptionalKeys<T> = { [K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never }[keyof T];

type PickRequired<T> = Pick<T, RequiredKeys<T>>;

type PickOptional<T> = Pick<T, OptionalKeys<T>>;

type Nullable<T> = { [P in keyof T]: T[P] | null };

type NullableOptional<T> = PickRequired<T> & Nullable<PickOptional<T>>;
content_copyCOPY

inHere Pro Portal Model Classes

https://rbardini.com/making-optional-properties-nullable-typescript/