Skip to content

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.

export let counter = 0;
export var name = "default";

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

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.