Subscribe on changes!

ref<type parameters> get Ref<UnwrapRef<type parameters>>

avatar
Oct 30th 2020

Version

3.0.2

Reproduction link

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzlApgMwDRwErrgXzjSghDgHIABANwFcUB6AY1MgGdgZgIA7AWgCGYYOQDcAKElpaPJl15xabFAAUBUZQEEoAczYAeACoA+ABTq9ALhwoWUACb62MKMB46sAngE9jASmttKAFvI2NEcTgouBYeZzh7ARgBOABeZHQw0wRCATY4Qz8JaJjeeMTkgEY0jLR9XDqTMxy4PJtG-2Lo1BhaKB44AG0AXQl8cSA

Steps to reproduce

import { ref, Ref } from 'vue';
function useParseArgs<T>(args: Record<string, any>): Array<T> {
    // const data: Ref<UnwrapRef<T>>
    const data = ref<T>({} as T);

    // const data1: Ref<T>.   I got what I wanted here 
    // but ({} as Ref<T>)  {} is not Ref
    const data1 = ref<Ref<T>>({} as Ref<T>);
    return [];
}

What is expected?

const data: Ref<T>

What is actually happening?

const data: Ref<UnwrapRef<T>>

// if T is type parameters, T extends Ref<infer V> is not valid
export declare type UnwrapRef<T> = T extends Ref<infer V> ? UnwrapRefSimple<V> : UnwrapRefSimple<T>;
avatar
Oct 30th 2020

image  😁

avatar
Jul 11th 2022

image  😁 Hi, where the origin doc?i don't find this on vue official document site