eslint-plugin-vue
eslint-plugin-vue copied to clipboard
Add test in `no-parsing-error` for template type assertions
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.
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
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.
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:
sorry it works with @typescript-eslint/parser
as parser for vue template 👍