Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-for typing issues #4958

Closed
robertmoura opened this issue Oct 28, 2024 · 2 comments
Closed

v-for typing issues #4958

robertmoura opened this issue Oct 28, 2024 · 2 comments
Labels
duplicate This issue or pull request already exists good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@robertmoura
Copy link

robertmoura commented Oct 28, 2024

Vue - Official extension or vue-tsc version

2.1.8

VSCode version

1.94.2

Vue version

3.5.12

TypeScript version

5.6.3

System Info

No response

package.json dependencies

No response

Steps to reproduce

Create a component with the following in it:

<template>
    <div v-for="item in items" :key="item.id" @click="onclick(item)">
        {{ item.name }}
    </div>
</template>

<script lang="ts" setup>
class Foo {

    constructor(public id: number, private _name: string) {}

    get name() {
        return this._name;
    }

}

const items: Foo[] = [];

function onclick(foo: Foo) {
    console.log(foo);
}
</script>

What is expected?

The typing should be correct

What is actually happening?

items is typed as Foo[] which is correct.

Screenshot 2024-10-29 at 9 17 44 am

item is simplified which is causing the issue. I believe it might be typed as Reactive<Foo> which may be breaking the typing.

Screenshot 2024-10-29 at 9 17 20 am

Here is the error I'm getting:

Screenshot 2024-10-29 at 9 27 39 am

Link to minimal reproduction

No response

Any additional comments?

I've notice there are a few issues I've found with generic components as well. I've seen issues with v-for and slots where functions expecting a particular type aren't working. They usually have types like UnwrapRef<T> or Reactive<T>.

@robertmoura
Copy link
Author

Similar to #4957

@KazariEX KazariEX closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@KazariEX KazariEX added duplicate This issue or pull request already exists and removed pending triage labels Oct 29, 2024
@johnsoncodehk johnsoncodehk added the good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first label Oct 29, 2024
@johnsoncodehk
Copy link
Member

Duplicate of #4948

@johnsoncodehk johnsoncodehk marked this as a duplicate of #4948 Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

No branches or pull requests

3 participants