Subscribe on changes!

$fromRefs is not returning UnwrapRef type

avatar
Aug 21st 2021

Version

3.2.4

Reproduction link

None

Steps to reproduce

<script lang="ts" setup>
import { toRefs } from 'vue';

const props = defineProps({
  isDisabled: {
    type: Boolean,
    default: false,
  },
  style: {
    type: String,
    default: 'primary',
  },
});

const { style } = $fromRefs(toRefs(props));

console.log(style); // correct output (primary) but incorrect type (Ref<string>)
</script>

What is expected?

I am expecting the type to unwrap the refs from toRefs(props)

What is actually happening?

The

// The type for `$fromRefs` is
ShallowUnwrapRef<ToRefs<Readonly<{
    isDisabled?: unknown;
    style?: unknown;
} & {
    isDisabled: boolean;
    style: string;
} & {}>>>

// The type for `style` is
Ref<string>

I am expecting it to be a string :thinking:


Is this correct behavior of the type or am I just missing something here?

avatar
Aug 22nd 2021

i can't reproduced it , can you provide a mini repo ?

avatar
Aug 22nd 2021

Somehow, creating a new project and migrating all previous setup to the new one fixed the issue. 🤔