Skip to content

importedNamespaceDynamicAccesses

Disallow computed member access on imported namespace identifiers.

✅ This rule is included in the performance preset.

Using computed member access (bracket notation) on namespace imports prevents bundlers from performing tree-shaking optimizations. When you dynamically access properties on a namespace import, bundlers cannot determine at build time which exports are actually used, forcing them to include the entire module in the final bundle.

Using static property access (dot notation) allows bundlers to analyze which specific exports are used and eliminate unused code during the build process. This can significantly reduce bundle size, especially for large libraries where you only use a subset of the available functionality.

import * as utils from "./utils";
function getValue(key: string) {
return utils[key];
}
import * as api from "api-library";
const method = getMethodName();
api[method]();

This rule is not configurable.

If you are not using a bundler that performs tree-shaking, or if you are working in an environment where bundle size is not a concern, you may choose to disable this rule.

However, even without tree-shaking concerns, static property access is generally more maintainable and provides better type checking than dynamic access.

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