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

Typescript errors for elements in v-for loop #3112

Closed
kachidk opened this issue May 3, 2023 · 8 comments
Closed

Typescript errors for elements in v-for loop #3112

kachidk opened this issue May 3, 2023 · 8 comments

Comments

@kachidk
Copy link

kachidk commented May 3, 2023

After the update to Volar v1.63, elements of iterable objects with explicit type any in v-for loops are inferred as type unknown

image

@rchl
Copy link
Collaborator

rchl commented May 3, 2023

Think that's probably correct because you have optional chaining there so that means that it considers the iterated over type being undefined | any[] and that would likely result in unknown or never.

@pjninnim
Copy link

pjninnim commented May 3, 2023

Seeing the same problem too after the update when optional chaining is not being used so it is not linked to that. The same problem was present in v1.6.2, everything was ok in v1.6.1.

@rchl
Copy link
Collaborator

rchl commented May 3, 2023

It might help the author to fix it if you provide specific example. Ideally a repo.

@pjninnim
Copy link

pjninnim commented May 3, 2023

The below shows a simple repo:
image
image

@Jahtila
Copy link

Jahtila commented May 3, 2023

Having the same problem, quite easy to replicate it:

<template>
  <div v-for="item of testArray" :key="item.id">
    {{ item.name }}
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  setup() {
    const testArray: any = [
      {id: 'one', name: 'Test One'},
      {id: 'two', name: 'Test Two'}
    ]
    return {
      testArray
    }
  }
})
</script>

image

Previously (on versions < 1.6.2) item was 'any' type as well and not 'unknown' and had no error.
(Forcing the testArray to be 'any' type here is just to replicate this problem, I'm aware that it should be properly typescripted.)

@mzuccaroli
Copy link

same problem here, I have updated vue-tsc to latest version but the problem persists

@so1ve
Copy link
Member

so1ve commented Aug 22, 2023

@mzuccaroli Would you mind opening a new issue with minimal reproduction?

@mzuccaroli
Copy link

@mzuccaroli Would you mind opening a new issue with minimal reproduction?

yes as soon as possible (I had some personal issues sory)
meanwhile the quick & dirty solution I found is downgrading vue-tsc to 1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants