Skip to content

Typescript: incorrect typings for unwrapped refs #3315

Closed
@shameleo

Description

Version

3.0.6

Reproduction link

https://github.com/shameleo/vue-ts-bug

Steps to reproduce

npm install
npm run dev

Open index.html browser and look console output.

What is expected?

If typescript is correct, console.log would print refs and their values.

What is actually happening?

I see values and undefined


Here essential code:

export default defineComponent({
  data: () => ({
    arr: [1, 2, 3].map((num) => ({ num: ref(num) })),
  }),
  mounted() {
    this.arr.forEach((el) => {
      console.log(el.num);
      // Typescript shows it is Ref<number>, but actually it is number
      console.log(el.num.value);
    });
  },
});

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.🐞 bugSomething isn't workingscope: types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions