vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.82k stars 396 forks source link

Can't define variables in inline event handler: "Property does not exist on type" #3258

Closed scscgit closed 1 year ago

scscgit commented 1 year ago

When defining a variable like this:

@click="() => {
  const x = 1
  if (x === 1) {
  }
}"

it yields two errors:

The code using such variable works correctly, and I've been using this syntax since Vue 2 with Vetur. After migrating to Vue 3 with Volar, this type safety and inference in VS Code fails.

image

so1ve commented 1 year ago

Notes:

When using script setup only, everything is good When using script lang="ts", only 'x' is declared but its value is never read. ts(6133) When using script setup lang="ts", 'x' is declared but its value is never read. ts(6133) and Property 'x' does not exist on type '...'. ts(2339)