Add suggestion diagnostic for enum computed string keys (#42468)#61839
Closed
yeomgahui wants to merge 2 commits intomicrosoft:mainfrom
Closed
Add suggestion diagnostic for enum computed string keys (#42468)#61839yeomgahui wants to merge 2 commits intomicrosoft:mainfrom
yeomgahui wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Author
|
@microsoft-github-policy-service agree |
|
Why this closed? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #42468
This PR adds a suggestion diagnostic when an enum member key uses a computed string like
["Hello"], to encourage clearer and more compatible code.Although such syntax is allowed in JavaScript, it can reduce readability and lead to subtle bugs. Based on the discussion in #42468, this PR introduces the following suggestion message:
This diagnostic is categorized as a Suggestion (code: 18062), so it does not affect existing code and is not a breaking change.
Note: The existing error for truly dynamic expressions (code 1164) remains unchanged.
Checklist:
mainbranchhereby runtestsenumComputedStringSuggestion.tsverifies the suggestionFeedback welcome 🙌