typescript-eslint: Bug: Vue 3 setup scripts are not considered as modules
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Issue Description
When having multiple components assign props to the same local variable name, something gets mixed up.
It seems that @typescript-eslint will always use the props of the first component (alphabetical order).
Please take a look at this example:
ComponentOne.vue:
<script setup lang="ts">
// no problems in this file
const props = defineProps<{
a: boolean;
b: string
}>();
if (props.a) {
console.log(`${props.b.replace('find', 'replace')}`)
}
</script>
ComponentTwo.vue:
<script setup lang="ts">
const props = defineProps<{
c: boolean;
d: string;
}>();
// triggers @typescript-eslint/strict-boolean-expressions
if (props.c) {
// triggers @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
console.log(`${props.d.replace('find', 'replace')}`)
}
</script>
When trying to log props.a or props.b in ComponentTwo.vue, I get not eslint errors (but this could obviously never actually run). When I rename one of the props variable names, I get no errors as well.
Found a related issue here: https://github.com/typescript-eslint/typescript-eslint/issues/4865
Reproduction Repository Link
https://github.com/alexkramer98/vue-props-eslint-repro
Repro Steps
- clone the repo
yarn installyarn lint
Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin |
5.48.1 |
@typescript-eslint/parser |
5.48.1 |
TypeScript |
4.9.4 |
ESLint |
8.31.0 |
node |
16.15.1 |
vue |
3.2.45 |
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 17 (5 by maintainers)
Ah got it, thanks. I imagine this might be an issue for Astro
.astrofiles too.Is there a way for Vue tooling to indicate to us that we should tell TypeScript it’s a module? I.e. turn on
isolatedModules?Failing that, maybe the right user action to take is enabling
isolatedModules?Just a heads up that as far as Nuxt projects goes,
moduleDection: forceis now the default configuration in nuxt’stsConfigfile. https://github.com/nuxt/nuxt/pull/26667@bradzacher I understand that, sorry if it came across as somehow demanding from my side. In fact, I’m aware this is probably not a typescript-eslint issue, but I was specifically interested in the proposed workaround than anything else, since this is an issue that (should) out of the box affects everyone (and not only Vue, but I also had it in Astro and, based on the description of typescript-eslint-parser-for-extra-files, also Svelte?), yet nobody is championing a PR, low activity on opened issues (or no issues in the parser’s for the respective languages), etc… Making me think it’s something exclusive of my setup (hence why I asked).
I’ve been subscribed for a while already!
Apologizes again!
as for now the only way to “solve” this is to force typescript to threat all files as modules, this can be done by
moduleDetection: forcein tsconfig https://www.typescriptlang.org/tsconfig#moduleDetectionthis is just a workaround and not an actual solution and it will not work for mixed codebases