Exporting from a typescript file
TLDR:
- no default exports
- no index files
- no paths aliases
- rely on vscode auto imports
- (optional) Import order:
- library services
- project services
- all components
1. No default exportsβ
Default exports mean devs can rename imports without reference to the export.
// default export renaming
import Comp from './aComponent';
import Component from './aComponent';
// named export renaming
import { Comp } from './aComponent';
import { Comp as Component } from './aComponent';
-
When you have named exports, a global search for the
Comp
will ALWAYS tell you 100% of the files that import the component. -
Named exports also play nicer with auto imports
2. Index filesβ
Barrel export index.ts files allows for nicer imports but are quite detrimental to tooling performance, avoid using them everywhere.
4. Rely on vscode auto importsβ
This makes moving code around when refactoring easier. vscode will ask you if you want to update the imports, and you just have to click yes!
If the above points have been followed, all imports should be updatable in this way.