eslint-plugin-vue icon indicating copy to clipboard operation
eslint-plugin-vue copied to clipboard

Add test in `no-parsing-error` for template type assertions

Open qnp opened this issue 2 years ago • 4 comments

What rule do you want to change?

no-parsing-error

Does this change cause the rule to produce more or fewer warnings?

Fewer errors.

How will the change be implemented? (New option, new default behavior, etc.)?

New default behavior.

Please provide some example code that this change will affect:

Any type assertion in templates. Here is a very naïve example:

<script setup lang="ts">
let x: string | number = 1
</script>

<template>
  {{ (x as number).toFixed(2) }}
</template>

What does the rule currently do for this code?

Parsing error: Unexpected token as

What will the rule do after it's changed?

No error.

Additional context

As stated by the official VueJS documentation, from which I took the above example, this syntax is valid.

qnp avatar Feb 02 '23 11:02 qnp

Are you using Vue 2 or Vue 3?

TypeScript syntax in template expressions is not allowed in Vue 2: https://v2.vuejs.org/v2/guide/migration-vue-2-7.html#Behavior-Differences-from-Vue-3

FloEdelmann avatar Feb 02 '23 13:02 FloEdelmann

It should work in Vue 3. But since there is no response, I'm closing this. Feel free to comment new information or open a new issue.

FloEdelmann avatar Feb 20 '23 15:02 FloEdelmann

I see that we indeed don't have a test case in https://github.com/vuejs/eslint-plugin-vue/blob/v9.17.0/tests/lib/rules/no-parsing-error.js to explicitly test TypeScript syntax in Vue 3, so maybe we don't support it.

A pull request to fix this would be appreciated :blush:

FloEdelmann avatar Oct 17 '23 11:10 FloEdelmann

sorry it works with @typescript-eslint/parser as parser for vue template 👍

joris-gallot avatar Oct 17 '23 11:10 joris-gallot