Description
Before You File a Documentation Request Please Confirm You Have Done The Following...
- I have looked for existing open or closed documentation requests that match my proposal.
- I have read the FAQ and my problem is not listed.
Suggested Changes
Looking through the examples in the docs for prefer-literal-enum-member, it's not very clear what behavior is actually banned by the rule, since 2 of the 5 examples in the invalid tab are invalid TS anyway, and 1 is not actually reported by the rule.
Furthermore some of the Valid examples are not valid TS either.
We should remove examples that have invalid TS (unless to point out explicitly "already banned by TS"), and ensure that each invalid case actually does trigger the rule.
I've annotated the docs example (view in playground):
const str = 'Test';
enum Invalid {
A = str, // Variable assignment
// BAD - not allowed by TS
B = {}, // Object assignment
// BAD - intentionally allowed by the rule
C = `A template literal string`, // Template literal
// BAD - not allowed by TS
D = new Set(1, 2, 3), // Constructor in assignment
E = 2 + 2, // Expression assignment
}
enum Valid {
A,
B = 'TestStr', // A regular string
C = 4, // A number
// BAD - not allowed by TS
D = null,
// BAD - not allowed by TS
E = /some_regex/,
}
Note when fixing the template literal example,
enum Miscellaneous {
// Allowed by TS starting in 5.0. Should be used in the Invalid examples instead of the current Template Literal example.
A = `A template string that interpolates ${str}`,
}
Affected URL(s)
https://typescript-eslint.io/rules/prefer-literal-enum-member/#examples
Additional Info
This issue is just to change the docs, but I think that it would also make sense to spin off another issue to check for and remove if appropriate any unnecessary complexity in the rule related to expressions that are already banned by TS.