Description
Reason: typescript-eslint/typescript-eslint#2865 (comment)
Hi, I'm using vue-eslint-parser
and typescript-eslint
in company project.
At the same time, I also help to contribute typescript-eslint
project for fixing vue problems.
This problems are only happens when using type rules in typescript-eslint
.
You need to add parserOptions.project
in project to enable it.
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md
There are two main issues:
performance issue
issues: #65, typescript-eslint/typescript-eslint#1180
The problem is that vue-eslint-parser
is designed with the AST not type information.
The vue-eslint-parser
will split code frame from template to @typescript-eslint/parser
.
typescript-eslint/typescript-eslint#1180 (comment)
Typescript program need to parse full project for generate type information.
When parsing code frame, typescript program will reparse file AST and rebuild type information in project.
The vue-eslint-parser
will pass more code frames and same file path in single Vue SFC.
Possible solutions:
- Ignore
parserOptions.project
to close get type information when pass code frame. - Try to use ESLint processors, like Svelte.
Ref: Add fragment options to lint code fragment for Vue SFC performance typescript-eslint/typescript-eslint#1180 (comment)
[no-unsafe-*] rules
issues: typescript-eslint/typescript-eslint#2865
Strictly speaking, it isn't a problem with this project.
The typescript program can't parse Vue SFC file directly.
You may think it's strange, but why is it working now?
Because @typescript-eslint/parser
will prioritize the content delivered from ESLint.
Typescript program will update by ESLint content not same as typescript program read.
But this problem is happens when ESLint not send file content and content from typescript program reading.
Example:
// App.vue
import HelloWorld from './components/HelloWorld.vue' // <- typescript program can't parse it. because it will read including template and style.
export default {
name: 'App',
components: {
HelloWorld // <- so type information is `any`
}
}
This problem will also have in <script setup>
RFC.
Possible solutions:
- Override
HelloWorld.vue
content. - Mock a
HelloWorld.vue.ts
file.
Maybe we need a common project for hacking typescript program.
Thanks for watching. Have a good day!