Skip to content

Commit

Permalink
fix(utilities): unref value before testing type for cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Sep 1, 2021
1 parent 3b9ddf9 commit fd5cc56
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/utilities/src/object/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import getType from '../type/get-type';

import {
unref,
UnwrapRef
UnwrapRef,
} from 'vue';

import type {
Expand Down Expand Up @@ -86,13 +86,14 @@ const CLONE_MAP = {
} as Record<RuntimeType | 'default', ((value: unknown) => unknown)>;

export default function clone<TValue = unknown>(value: TValue): UnwrapRef<TValue> {
if (typeof value !== 'object' || value === null) {
return value as UnwrapRef<TValue>;
const input = unref(value);

if (typeof input !== 'object' || input === null) {
return input as UnwrapRef<TValue>;
}

const type = getType(value);
const type = getType(input);
const cloner = CLONE_MAP[type] || CLONE_MAP.default;
const input = unref(value);

return cloner(input) as UnwrapRef<TValue>;
}

0 comments on commit fd5cc56

Please sign in to comment.