diff --git a/types/Optional.ts b/types/Optional.ts new file mode 100644 index 0000000..2929cc0 --- /dev/null +++ b/types/Optional.ts @@ -0,0 +1,18 @@ +/** + * Makes some properties of a record optional. + */ +export type Optional> = Omit & { [K in keyof T]?: T[K] } + +/* + * Example: + * type CartItem = { + * id: string, + * sku: string, + * quantity: number, + * } + * + * function addItem(item: Optional) { + * // typeof item: { id?: string, sku: string, quantity?: number } + * ... + * } + */ diff --git a/types/index.ts b/types/index.ts index efe43e2..02cd181 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,2 +1,3 @@ export * from './Branded.ts' export * from './DeepPartial.ts' +export * from './Optional.ts'