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

Support typed strings on no-unused-keys #609

Open
SimonSimCity opened this issue Feb 19, 2025 · 0 comments
Open

Support typed strings on no-unused-keys #609

SimonSimCity opened this issue Feb 19, 2025 · 0 comments

Comments

@SimonSimCity
Copy link

SimonSimCity commented Feb 19, 2025

What rule do you want to change?

no-unused-keys

Does this change cause the rule to produce more or fewer warnings?

fewer

How will the change be implemented? (New option, new default behavior, etc.)?

Read the type for the input of the translation-function to determine the possible strings.

Please provide some example code that this change will affect:

<script lang="ts" setup>
let status: 'loading' | 'error' | 'success' = 'loading';
</script>

<template>
<span>{{ t(`global.${status}` }}</span>
</template>

What does the rule currently do for this code?

I guess it does ignore all template-strings, because I get a list of all these translation-keys reported as being unused.

What will the rule do after it's changed?

It recognizes, that the only available values (based on the given types) are global.loading, global.error and global.success, and will remember all those as being used. If not already, this could also be used in the rule @intlify/vue-i18n/no-missing-keys to determine possibly missing keys.

To be clear, this rule is not for variables typed as string. There are ways of mapping a union of fixed strings or extending it (see https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html).

Additional context

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

No branches or pull requests

1 participant