TypeScript Configuration and Tooling
tsconfig options, declaration files, typing third-party code and keeping type checks in your workflow.
Intermediate · about 3 hours · difficulty 3/5
Learn first: TypeScript Fundamentals, Build Tools and Bundlers
Knowing the type system is half the job; the other half is configuring a project so TypeScript helps rather than annoys.
tsconfig.json essentials
strict: turns on the checks that matter (strictNullChecks,noImplicitAnyand friends).targetandlib: which JavaScript features and built-in APIs (includingDOM) are available.moduleandmoduleResolution: use"bundler"for Vite-style apps and"NodeNext"for Node packages.jsx:"react-jsx"for React projects.paths: import aliases like@/components(the bundler must agree).noEmit: let the bundler produce JavaScript whiletsconly type checks.- Extra safety worth enabling:
noUncheckedIndexedAccess,exactOptionalPropertyTypes(stricter, optional).
Declaration files
Libraries ship types as .d.ts files, either bundled or via DefinitelyTyped (@types/lodash). For untyped modules or globals, write a small declare module shim. Vite projects use vite-env.d.ts to type import.meta.env.
Workflow
- Bundlers like Vite and esbuild strip types without checking them. Run
tsc --noEmitin a script and in CI. - Use editor features: go to definition, rename symbol, quick fixes. They are the everyday payoff.
- Migrate JavaScript gradually with
allowJsandcheckJsif needed.
Good enough to move on
You can read and adjust a tsconfig, add a path alias that works in both TypeScript and Vite, type environment variables and fix a "could not find a declaration file" error properly.
Key concepts
- tsconfig strict and target options
- moduleResolution and jsx settings
- Path aliases
- Declaration files and @types
- Type checking in CI with tsc --noEmit
- Typing import.meta.env
- Gradual migration from JavaScript
Mini project
Set up a Vite plus TypeScript project from scratch with strict mode, an @/ alias, typed environment variables, and a CI-ready typecheck script that fails on errors.
Check yourself
If Vite builds your app successfully, why can it still contain type errors?
Free resources
- TSConfig Reference (TypeScript)
- Declaration Files (TypeScript)
- Vite TypeScript features (Vite)