Vue / Typescript: Send ref as function param

What is the type of a ref param in a function?

example:

function( data: refType ) {
console.log(data.value) // ref as function parameter
}

It is of type Ref, which you can import from vue.

import { Ref } from 'vue'

function myFunc(data: Ref) {
    console.log(data.value)
}

If you know the data type of the ref you can also be more specific. For example, if data was a ref of a string:

import { Ref } from 'vue'

function myFunc(data: Ref<string>) {
    console.log(data.value)
}

Or you can even use generics if it can be of many/any type(s).

import { Ref } from 'vue'

function myFunc<T>(data: Ref<T>) {
    console.log(data.value)
}
1 Like

Thank you very much really. Just what I needed. I am really grateful to you.