isRef()
Type guard that checks whether a value is a ref.
Syntax
isRef(r: unknown): r is Ref Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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().