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

Default parserOptions.ecmaFeatures.jsx: true breaks type assertion parsing in setup scripts #55

Open
dmolesUC opened this issue Mar 30, 2023 · 0 comments

Comments

@dmolesUC
Copy link

Steps to reproduce:

  1. Clone dmolesUC/ts-test for a complete reproducible example, or:

    1. create a Vue3/TypeScript project by running yarn create vite and selecting Vue and TypeScript

    2. add and configure ESLint, including this plugin

    3. modify components/HelloWorld.vue to contain the code below:

      <script setup lang="ts">
      import { Ref, ref } from 'vue'
      
      defineProps<{ msg: string }>()
      
      const count: Ref<number | undefined> = ref(0)
      
      function incrementCount() {
        const c = <number>count.value // <- type assertion is here
        count.value = c + 1
      }
      </script>
  2. Run yarn eslint --ext .js,.ts,.vue src

Expected

  • Code lints without errors; or, at least, ESLint is able to parse the Vue component source file.

Actual

  • Closing brace of the incrementCount() function produces the following parsing error:

    /Users/david/Work/Scratch/ts-test/src/components/HelloWorld.vue
      12:0  error  Parsing error: Unexpected token. Did you mean `{'}'}` or `&rbrace;`?
    
    ✖ 1 problem (1 error, 0 warnings)
    

Workaround

  • in .eslintrc.cjs, add ecmaFeatures: { jsx: false } to parserOptions

Note

I originally filed this as vuejs/vue-eslint-parser#177, but @ota-meshi identified the issue as being the jsx config in eslint-config-typescript/index.js.

It's not clear to me why JSX support needs to be enabled by default for Vue projects, which I think tend not to use it that often. But at least this issue documents the workaround.

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

1 participant