The prefer-const rule flags a let declaration when its value is never reassigned and recommends const instead. ESLint reports the issue while checking TypeScript files against the configured rules. section 6.3
Typical lint result
Running npx eslint . can report errors such as “'message' is never reassigned. Use 'const' instead” and identify them as prefer-const violations. The same output can flag printMessage and total.
Configure the rule according to the project’s priorities:
- Keep prefer-const enabled to receive warnings about let declarations that should use const. section 6.3
- Set "prefer-const": 0 in the rules section of .eslintrc to disable the rule globally. section 6.3.1
- Disable rules selectively when a warning is useful generally but inappropriate for a particular statement; the supplied example applies this approach to no-debugger. section 6.3.1
