Type Alias Overwrite<T1, T2>

Overwrite<T1, T2>: {
    [P in Exclude<keyof T1, keyof T2>]: T1[P]
} & T2

Returns a new type consisting of all properties declared for an input type T2 overlaid on the properties of type T1. Any definitions in T2 replace those previously defined in T1. This can be useful for redefining the types of properties on T1 with values from an inline type T2, perhaps to change their type or to make them optional.

type NameAndStringValue = { name: string, value: string }
type NameAndOptionalNumericValue = Overwrite<NameAndValue, { value?: number }>
// type of NameAndOptionalNumericValue -> { name: string } & { value?: number | undefined }

Type Parameters

  • T1
  • T2