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

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

Closed
scscgit opened this issue Jun 8, 2023 · 1 comment · Fixed by #3280
Closed
Labels
bug Something isn't working

Comments

@scscgit
Copy link

scscgit commented Jun 8, 2023

When defining a variable like this:

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

it yields two errors:

  • 'x' is declared but its value is never read. ts(6133)
  • Property 'x' does not exist on type 'MyComponent'. ts(2339)

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
Copy link
Member

so1ve commented Jun 14, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants