Skip to content

clone ​

The clone() function performs a typed deep copy of a value while preserving its structure and types.

Interactive example ​

Syntax ​

typescript
type SimplifyTypeForce<
	GenericInput extends unknown
> = GenericInput extends object 
	? {
    	[Prop in keyof GenericInput]: SimplifyTypeForce<GenericInput[Prop]>;
	} 
	: GenericInput;

function clone<
	GenericInput extends unknown = unknown
>(
	input: GenericInput
): SimplifyTypeForce<GenericInput>;

Parameters ​

  • input : Value to deep clone.

Return value ​

A new value structurally identical to the original, with the simplified type (SimplifyTypeForce).

See also ​

Released under the MIT license.