Skip to content

vue-prefer-shallow-ref ​

ref<T>(...) where T is readonly: readonly T[], Readonly<...>, ReadonlyArray, ReadonlyMap, ReadonlySet.

Why: ref makes everything inside its value reactive too, wrapping every nested object and array in a proxy as you read it, so it can notice changes made in place. A readonly type says nothing changes in place: the value is only ever replaced. shallowRef tracks exactly that, replacing .value, and skips the proxies. On a list of a thousand loaded rows, that is a thousand proxies fewer, and reading them is faster (Vue docs). Guide: Vue.

ts
import { ref } from "vue";

type User = { readonly id: string; readonly name: string };

export function useUsers() {
  const users = ref<readonly User[]>([]);
  const replace = (next: readonly User[]): void => {
    users.value = next;
  };
  return { users, replace };
}
✓ Accepted0 diagnostics
ts
import { shallowRef } from "vue";

type User = { readonly id: string; readonly name: string };

export function useUsers() {
  const users = shallowRef<readonly User[]>([]);
  const replace = (next: readonly User[]): void => {
    users.value = next;
  };
  return { users, replace };
}

Quick fix: Use shallowRef (adds the import).

What the rule can't see: a ref without a type argument, and readonly types behind an alias (ref<Users>() with type Users = readonly User[]).

A warning in the recommended oxlint preset.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra