Path mapping & module resolution
Configure path aliases with baseUrl/paths, understand how TS resolves modules, and avoid common pitfalls.
Intro
Goal: Replace long relative imports with path aliases and understand TypeScript`s module resolution rules to keep imports clean.
tsconfig paths
Set baseUrl (project root for non-relative imports) and map aliases in paths. Keys can use * globs.
// file: tsconfig.json (excerpt)
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@utils/*": ["utils/*"],
"@components/*": ["components/*"]
}
}
}All lessons in this course
- ES Modules (named vs default), re-exports
- Ambient declarations (.d.ts) & third-party typings
- Path mapping & module resolution