Skip to content

Latest commit

 

History

History
92 lines (63 loc) · 1.67 KB

File metadata and controls

92 lines (63 loc) · 1.67 KB

typelab / utils / ObjectAssign

type ObjectAssign<Target, Source> = _ObjectAssignPreCheck<Target, Source, Target extends Primitive ? _ObjectAssignPrimitive<Target, Source> : Target extends ReadonlyArray ? _ObjectAssignArray<Target, Source> : IsObjectLiteral<Target> extends true ? _ObjectAssignObject<Target, Source> : Target & Source>;

Assign properties of Source into Target.

The result of type follows the actual result of Object.assign.

Type Parameters

Type Parameter Default type Description

Target

The type to receive the assignment.

Source

never

The type to be assigned to the Target.

Returns

A new type that combines both Target and Source.

Example

// { a: string; b: string; c: boolean }
type Assign1 = ObjectAssign<{ a: string; b: number }, { b: string; c: boolean }>;

// { a: string; 0: string }
type Assign2 = ObjectAssign<{ a: string }, [string]>;

// { [x: number]: string, a: string }
type Assign3 = ObjectAssign<{ a: string }, string[]>;

// [number, number]
type Assign4 = ObjectAssign<[string], [number, number]>;

// (string | number)[]
type Assign5 = ObjectAssign<string[], [number, number]>;

// (string | number)[]
type Assign6 = ObjectAssign<string[], number[]>;

// [number, string]
type Assign7 = ObjectAssign<[string], { 0: number; 1: string }>;

// (string | number)[]
type Assign8 = ObjectAssign<[number], 'str'>;

// { [x: number]: string, a: string }
type Assign9 = ObjectAssign<{a: string}, 'str'>;