Thanks to visit codestin.com
Credit goes to github.com

Skip to content

return type of unref includes ShallowRef if the passed type is ShallowRef | ComputedRef | MaybeRef #11356

@NicolaiHorlacher

Description

@NicolaiHorlacher

Vue version

3.4.31

Link to minimal reproduction

https://play.vuejs.org/#eNqtU9tq4zAQ/ZVBL91CcMlmn7LewO7Sh13ohTb0SVBcZ+K4lSUhjdKU1P/ekVynpjdaKMZCmhnpnDOXrfhtbbYOKKYi96WrLYFHChZUoatfUpCXYiZ13VjjCOjOImzhfFUoZW7PcDmCv6axgXCRDkfF3RWmHS/QwtKZBvb4+b2fuze2ELR75pU6fsugS6qN7gLm6Gn8jXBD0wFg7snVuprB/RB5YO0p9Kb9KXQ72EoN4Fice0RIj+8zs/Z19O/voX8hzuSTKj8IlR90BeXy8YGwsaog5BNAvhrPuioQ4/v8gM/xwiBIjLj2pdHLusquvdHcIAlNipIZ1QrdiY0yuD+mHY/oSwL+Jxu5gKPeXq6wvHnFfu030SbFqUOPbo1S7HxUuAqpcx+eH7OwgbMxi6A4+h3nGXqjQuTYhf0JesG0B3GJ7b/UlpzNuT/cEGrfi4pEY2Sb4qXgRo3FeEv6E91J9iPd4ypwFpWpMvKcvk/O0LPxcYMBInNRqIAvI+K/6y8GnnNevnaEGGDXcY80+p5jVxsX1ny5RhfzyKo5GdlkLNoHV8KK9A==

Steps to reproduce

unref and toValue resolve the type incorrectly if the passed type is ShallowRef | ComputedRef | MaybeRef.

What is expected?

The return type of the text function should be string.

function test(text: ShallowRef<string> | ComputedRef<string> | MaybeRef<string>) {
  return unref(text);
}

What is actually happening?

But it is string | ShallowRef<string> instead.

System Info

Typescript 5.5.3

Any additional comments?

function test(text: ShallowRef<string> | MaybeRef<string>) {
  return unref(text);
}

and

function test(text: ShallowRef<string> | ComputedRef<string>) {
  return unref(text);
}

have the only string as return type as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions