isRef()

Type guard that checks whether a value is a ref.

Since Vue 3.0 Spec ↗

Syntax

isRef(r: unknown): r is Ref

Parameters

NameTypeRequiredDescription
r unknown No The value to test.

Returns

boolean — True when the value is a ref.

Examples

<script setup lang="ts">
import { ref, isRef } from 'vue';

const a = ref(1);
const b = 2;
console.log(isRef(a)); // true
console.log(isRef(b)); // false
</script>

Notes

isRef narrows the TypeScript type to Ref, useful in utilities that branch on ref vs. plain value. For simply reading the inner value regardless, prefer unref().