💼 This rule is enabled in the ✅ recommended
config.
💡 This rule is manually fixable by editor suggestions.
structuredClone
is the modern way to create a deep clone of a value.
const clone = JSON.parse(JSON.stringify(foo));
const clone = _.cloneDeep(foo);
const clone = structuredClone(foo);
Type: object
Type: string[]
You can also check custom functions that creates a deep clone.
_.cloneDeep()
and lodash.cloneDeep()
are always checked.
Example:
{
'unicorn/prefer-structured-clone': [
'error',
{
functions: [
'cloneDeep',
'utils.clone'
]
}
]
}
// eslint unicorn/prefer-structured-clone: ["error", {"functions": ["utils.clone"]}]
const clone = utils.clone(foo); // Fails