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

no-dynamic-keys to recognize const-types #486

Open
SimonSimCity opened this issue Mar 27, 2024 · 0 comments
Open

no-dynamic-keys to recognize const-types #486

SimonSimCity opened this issue Mar 27, 2024 · 0 comments

Comments

@SimonSimCity
Copy link

What rule do you want to change?

no-dynamic-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.)?

When concatenating a string with a const, typescript knows the possible strings which this expression can result in. For this reason, this rule could be extended to allow dynamic keys, when they result in a fixed list of strings. Those strings would then have to be taken into consideration for other rules as well (e.g. no-missing-keys-in-other-locales).

Please provide some example code that this change will affect:

<script lang="ts" setup>
const searchFilter = ref<
  | "All"
  | "Speeches"
  | "Music"
  | "Albums"
  | "Contributors"
  | "Podcasts"
  | "Playlists"
>("All");
</script>

<template>
  <div>{{ t(searchFilter) }}</div>
</template>

What does the rule currently do for this code?

It reports the code.

What will the rule do after it's changed?

It won't report the code.

Additional context

Might be problematic that even typescript itself doesn't resolve string-manipulation...

const searchFilter = ref<
  | "All"
  | "Speeches"
  | "Music"
>("All");

// The type of this variable is `string`, even though it could be determined as `test-All`, `test-Speeches` or `test-Music`...
const searchFilter2 = `test-${searchFilter}`
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