Skip to content

Support typed strings on no-unused-keys #609

Open
@SimonSimCity

Description

@SimonSimCity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions