Rule proposal: prefer as const
#312
Labels
enhancement: new plugin rule
New rule request for eslint-plugin
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
In a lot of our code we have to cast string literals to literals types to conform to types so assignments work:
This is more common when using React HOCs but above example demonstrate the problem well enough.
With TypeScript 3.4 we'll have the
as const
literal expression which should be preferred to string or number literal types in this case because changing the value does not require changing the type.Our example code would be better written as:
More examples:
Rule name
Please suggest rule name. I'm not sure how this rule should be named
Options
I can't think of any configurability for this rule
The text was updated successfully, but these errors were encountered: