Skip to content

Commit 1ac85ee

Browse files
authored
Fix false positives for type def with script setup in ts no-unused-vars (#191)
1 parent fde53d1 commit 1ac85ee

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Diff for: src/script-setup/scope-analyzer.ts

+6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ function analyzeUsedInTemplateVariables(
205205

206206
variable.references.push(reference)
207207
reference.resolved = variable
208+
209+
if (reference.isTypeReference) {
210+
// @typescript-eslint/no-unused-vars treats type references at the same position as recursive references,
211+
// so without this flag it will be marked as unused.
212+
;(variable as any).eslintUsed = true
213+
}
208214
}
209215

210216
function processVExpressionContainer(node: VExpressionContainer) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"@typescript-eslint/no-unused-vars": "error"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script setup lang="ts">
2+
import MyComponent from "./components/MyComponent.vue";
3+
interface Foo {
4+
foo?: string;
5+
}
6+
type Bar = string;
7+
</script>
8+
9+
<template>
10+
<MyComponent
11+
:foo="{} as Foo"
12+
:bar="'s' as Bar"
13+
/>
14+
</template>

0 commit comments

Comments
 (0)