Sub topic 12
Using `tsc` with editors, bundlers, and runners
This chapter assumes you understand JavaScript functions, objects, and modules. You should also know how to use a terminal, npm, and package.json, and have Node.js installed.
A TypeScript project can use several tools at once. The TypeScript compiler, usually called tsc, checks types and can emit JavaScript. An editor gives immediate diagnostics while you work. A bundler combines modules and prepares browser or production assets. A runner executes source code during development. These tools overlap, but they do different jobs.
The role of each tool
tsc is the authority for TypeScript's type system. When you run tsc --noEmit, it checks your project without creating JavaScript files. When you run it normally, it can check the project and emit JavaScript, source maps, and declaration files.
An editor such as Visual Studio Code usually runs a TypeScript language service in the background. It can underline errors, show inferred types, and offer refactoring before you run a command. Editor diagnostics are useful feedback, but your continuous integration (CI) system should run an explicit command such as npx tsc --noEmit.
A bundler such as Vite, esbuild, webpack, or Rollup transforms and combines modules. It may transpile TypeScript syntax quickly, but many bundlers do not perform complete type checking. A successful bundle therefore does not always mean that the project has no type errors.
A runner executes code. Node.js can run emitted JavaScript. Tools such as tsx can run TypeScript directly by transpiling it during development. This is convenient, but the runner may not replace a separate type-checking step.
Common project arrangements
A Node.js library or simple server can let tsc perform both checking and JavaScript emission:
{
"scripts": {
"build": "tsc",
"typecheck": "tsc --noEmit",
"start": "node dist/index.js"
}
}A browser application often gives the bundler responsibility for development and production output. In that arrangement, tsc checks types while the bundler handles module resolution, asset imports, code splitting, and minification:
{
"scripts": {
"dev": "vite",
"build": "tsc --noEmit && vite build",
"typecheck": "tsc --noEmit"
}
}The && means that vite build runs only when type checking succeeds. Some teams intentionally allow bundling and type checking to run in parallel for speed, but CI must still report type-checking failures clearly.
A runner-based workflow might look like this:
{
"scripts": {
"dev": "tsx watch src/index.ts",
"typecheck": "tsc --noEmit",
"build": "tsc"
}
}Here, tsx provides a fast edit-run cycle. The build script still uses tsc to produce the project's official output.
Choosing the boundary
Use tsc for emitted JavaScript when you want a direct, predictable compiler output, especially for libraries and Node.js services. Use a bundler when you need browser assets, code splitting, tree shaking, or special file handling. Use a runner when fast local execution matters more than producing distributable files.
A common error is configuring tsc to emit files that another tool also emits. This creates duplicate or confusing output. If a bundler owns emission, use noEmit in tsconfig.json or pass --noEmit in the type-check script. If tsc owns emission, point outDir at a clean distribution directory and run the generated JavaScript.
Another error is relying only on editor warnings. Editors can use a different TypeScript version or configuration than CI. Install TypeScript locally and invoke it through npx or an npm script so the project controls the version.
Exercise
A Vite application starts successfully, but CI should reject code with TypeScript errors. Which command should the CI type-check job run?
Show answer
Run npx tsc --noEmit or the equivalent npm run typecheck script. Vite's successful build does not guarantee complete type checking.