language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Vue TSC & computed-refs

Open louis49 opened this issue 9 months ago • 2 comments

I do not understand why this have an error with transpiling with vue-tsc :

import { computed, ComputedRef, UnwrapNestedRefs } from "vue";

interface ConcreteTest {
    val: ComputedRef<string>;
}

interface Store {
    registers: ConcreteTest[];
}

class StoreManager {
    public store: UnwrapNestedRefs<Store> = {
        registers: []
    };

    addRegisters(){
        const val = computed(() => { return "0xaa" });
        this.store.registers.push({ val }); // => The expected type comes from property 'val' which is declared here on type '{ val: string; }'
    }
}

You can check it here : https://github.com/louis49/demo-vue-ts-computed-refs.git with npm build

louis49 avatar May 07 '24 14:05 louis49

This is likely a vue core issue

so1ve avatar May 08 '24 02:05 so1ve

Попробуй убрать UnwrapNestedRefs. Или { val: val.value}

teleskop150750 avatar May 14 '24 04:05 teleskop150750

Hey there, as there have been many fixes in the last 2.x versions: Please let us know if you're still encountering this issue. Otherwise kindly close this one, thanks!

davidmatter avatar Aug 07 '24 07:08 davidmatter

This is expected. As said in https://github.com/vuejs/language-tools/issues/4350#issuecomment-2109275407, you can use { val: val.value }, or remove UnwrapNestedRefs. In real-world cases, you may need to use shallowRef instead of ref

kermanx avatar Aug 13 '24 13:08 kermanx