Module
Function Coupling
Fan-Out: how many distinct modules does this file depend on?
What it measures
Function Coupling measures the fan-out of a module — the number of distinct import sources it depends on. A high fan-out means the module has many external dependencies, making it harder to change, test in isolation, and understand.
tsmetrics classifies imports into three categories:
- Relative — paths starting with
./or../(intra-project) - Package — npm packages, Node built-ins, or path aliases
- Type-only —
import type { … }imports (erased at runtime)
How it's computed
Fan-Out = |distinct import sources|
Multiple imports from the same source count as 1.
Dynamic imports and re-exports are not counted.
If a source appears in both value and type-only imports,
it is classified as a value (runtime) dependency.
Example
TypeScript — fan-out: 4
import { useState } from 'react'; // package import { db } from './database'; // relative import { logger } from './logger'; // relative import { db } from './database'; // duplicate → still 1 import type { User } from './types'; // type-only // distinct sources: react, ./database, ./logger, ./types = 4
Tip: A fan-out above 10 is a warning sign. Consider whether the module is doing too much, or whether some imports could be consolidated via a shared utility layer.
Edit on GitHub