exportMutables
Reports exporting mutable bindings (let or var).
✅ This rule is included in the ts logical presets.
Exporting mutable bindings (let or var) can lead to confusing behavior.
When an exported variable is changed, consumers of the module will see the updated value, which can be unexpected and difficult to debug.
This rule requires exported variables to be declared with const to ensure they cannot be reassigned.
Examples
Section titled “Examples”export let counter = 0;export var name = "default";export const counter = 0;export const name = "default";let internalCounter = 0;
export function getCounter() { return internalCounter;}
export function increment() { internalCounter++;}When Mutation Is Necessary
Section titled “When Mutation Is Necessary”If you need to expose a value that changes over time, consider these alternatives:
- Export getter and setter functions
- Export an object with methods to access and modify the value
- Use a state management pattern
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you intentionally use mutable exports for module-level state that consumers are expected to observe, you may disable this rule. However, this pattern can be confusing and is generally discouraged.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
import/no-mutable-exports - Oxlint:
import/no-mutable-exports
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.