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

Script setup + eslint = unused vars #47

Closed
iamrgroot opened this issue Jan 22, 2021 · 9 comments
Closed

Script setup + eslint = unused vars #47

iamrgroot opened this issue Jan 22, 2021 · 9 comments
Labels
question Further information is requested

Comments

@iamrgroot
Copy link

Is there any way to let eslint check whether the constants in a script tag with 'setup' sugar are being used in the template? I would prefer it to keep using the rule in my projects.

The following code triggers the '@typescript-eslint/no-unused-vars' eslint rule for the props and increment consts.

<template>
    <h1> {{ msg }} </h1>
    <p>
        Clicks {{ count }}
    </p>
    <p>
        <button @click="increment">
            Increment
        </button>
    </p>
</template>

<script setup lang="ts">
import { ref, defineProps } from 'vue';

const props = defineProps({
    msg: {
        type: String,
        required: true,
    }
});

const count = ref(0);

const increment = (): number => count.value++;
</script>

image

@johnsoncodehk
Copy link
Member

hi @iamrgroot, it may can't be fix now, relate: #34 (comment)

@soulsam480 can you share your experience?

@johnsoncodehk johnsoncodehk added the question Further information is requested label Jan 22, 2021
@johnsoncodehk
Copy link
Member

can you disable @typescript-eslint/no-unused-vars, and use tsconfig.json with noUnusedLocals: true for replacement?

noUnusedLocals is handle by volar so it can correctly report with <script setup>.

@antfu
Copy link
Member

antfu commented Jan 23, 2021

noUnusedLocals: true

That's an awesome tip, thanks! (maybe you can document it :P

@johnsoncodehk
Copy link
Member

@antfu Okay, let me open a tips topic to Discussions late, there has more I can share :)

@CharlesOkwuagwu
Copy link

On this issue, to be clear are, you recommending we set noUnusedLocals: false in tsconfig.json?

Setting noUnusedLocals: true brings: 'props' is declared but its value is never read.ts(6133)

@johnsoncodehk
Copy link
Member

@CharlesOkwuagwu this is a replacement for @typescript-eslint/no-unused-vars, if you don't use eslint with no-unused-vars, you don't need to config noUnusedLocals option because noUnusedLocals default is false.

@Liwoj
Copy link

Liwoj commented Sep 1, 2021

Check this

@xinlei3166
Copy link

mark

@Johnsoct
Copy link

I know the new documentation says you don't need any special config settings with Vue + TS to get this working, but that's not the case. I'm using TS 5.X and the most updated version of Vue 3, and I still had to disable the JS and TS rules for no-unused-vars and then use noUnusedLocals in the TSConfig.

This should really, really be mentioned in this section of the documentation: https://vuejs.org/guide/typescript/overview.html#volar-takeover-mode

It would have saved me hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants