TypeScript
/Advanced
Module Resolution
Definition
The process the TypeScript compiler uses to figure out what an import refers to. (e.g., figuring out exactly where `import { React } from 'react'` lives on your hard drive).
Explain Like I'm New
When you tell TypeScript 'Go get the `lodash` package', Module Resolution is the GPS algorithm it uses to hunt through the `node_modules` folder, check `package.json` files, and finally locate the `index.d.ts` file so it can read the types.
Real World Example
Configuring your project to use `"moduleResolution": "node16"` so that TypeScript understands native ES Modules in Node.js environments.
Common Use Cases
- •Monorepo setups
- •Fixing 'Cannot find module' errors
- •Library authoring
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- What are the two main module resolution strategies in TS?
intermediate
- What happens if TS finds the `.js` file but cannot find the `.d.ts` file?
advanced
- What is the purpose of the `types` array in `tsconfig.json`?