Skip to content

Commit

Permalink
Fix false positives for type def with script setup in ts no-unused-va…
Browse files Browse the repository at this point in the history
…rs (#191)
  • Loading branch information
ota-meshi committed May 3, 2023
1 parent fde53d1 commit 1ac85ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/script-setup/scope-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ function analyzeUsedInTemplateVariables(

variable.references.push(reference)
reference.resolved = variable

if (reference.isTypeReference) {
// @typescript-eslint/no-unused-vars treats type references at the same position as recursive references,
// so without this flag it will be marked as unused.
;(variable as any).eslintUsed = true
}
}

function processVExpressionContainer(node: VExpressionContainer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"@typescript-eslint/no-unused-vars": "error"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
import MyComponent from "./components/MyComponent.vue";
interface Foo {
foo?: string;
}
type Bar = string;
</script>

<template>
<MyComponent
:foo="{} as Foo"
:bar="'s' as Bar"
/>
</template>

0 comments on commit 1ac85ee

Please sign in to comment.