I was refactoring some code, namely organizing the imports (sorting, removing unused, etc.)
I had three files:
ControllerOverrideService (uses default export)RunServiceController depends on both OverrideService & RunService.RunService depends on OverrideServiceI came across this issue:
In Controller.ts, originally the order of imports was like this:
import { RunService } from '../services/RunService';
import OverrideService from '../services/OverrideService';
When imports were sorted alphabetically the code stopped working properly:
import OverrideService from '../services/OverrideService';
import { RunService } from '../services/RunService';
Giving an error:
TypeError: OverrideService_1.default.overrideDependencyValidator is not a function
When I changed the default export to a named export in OverrideService, and updated the imports to be like this, the issue is no longer there.
import { OverrideService } from '../services/OverrideService';
import { RunService } from '../services/RunService';
I did some research but couldn't find any information on default vs named exports aside from tree-shaking and other irrelevant differences.
What would be the reason a default export cause an issue when reordering imports?