Install and Run TypeScript
For a project, install TypeScript as a development dependency so everyone and CI use the same version. npx tsc --init creates a starting tsconfig.json; npx tsc compiles the project according to that configuration. Avoid relying on an arbitrary globally installed compiler for team projects.
A minimal Node-oriented project often has src/ as input and dist/ as output. The exact module and target settings depend on whether the project uses Node ESM, CommonJS, a browser bundler, or a framework. Follow the runtime's module conventions instead of copying a configuration without understanding it.
Project setup commands
npm init -y
npm install --save-dev typescript
npx tsc --init
npx tsc --noEmit💡 These commands create a package, install a local compiler, create a config, and type-check without emitting output. Add a build script and choose module settings that match the project's runtime.
Key Takeaways
- Install TypeScript locally for reproducible builds.
tsconfig.jsoncontrols the compiler's project behavior.- Choose module settings to match your runtime and tooling.
Knowledge Check
Why is a local TypeScript development dependency usually preferable?