TypeScript is usually installed through npm. For most projects, install it as a development dependency so the project controls its own compiler version. This avoids surprises when different developers have different global TypeScript versions installed.
You can also use TypeScript through frameworks such as Angular, Next.js, Vite, NestJS, Remix, or Vue. Even when a framework hides most setup details, understanding the plain compiler workflow helps you debug errors and read project configuration confidently.
npm init -y
npm install --save-dev typescript
npx tsc --version
Create a file named app.ts. TypeScript files usually use the .ts extension. The compiler checks the TypeScript code and emits JavaScript that Node.js or the browser can run.
TypeScript itself is not a runtime. The type annotations are removed during compilation, and the final output is JavaScript.
const message: string = "Hello TypeScript";
const year: number = 2026;
console.log(`${message} in ${year}`);
The TypeScript compiler is called tsc. When you compile app.ts, TypeScript checks the types and creates app.js. The JavaScript file is what you execute with Node.js.
If the compiler finds a type error, it reports the problem with a file name and line number. Fix those errors early instead of waiting until runtime.
| Command | Purpose |
|---|---|
npx tsc app.ts | Compile one TypeScript file. |
node app.js | Run the generated JavaScript with Node.js. |
npx tsc --watch | Keep the compiler running and rebuild after changes. |
npx tsc app.ts
node app.js
A tsconfig.json file stores compiler settings for the whole project. Once it exists, you can run npx tsc without passing every file manually.
The config also tells TypeScript which folders belong to the project, what JavaScript version to target, whether strict checking is enabled, and where output files should be written if the compiler emits JavaScript.
npx tsc --init
npx tsc
A common beginner structure keeps TypeScript source files in src and compiled JavaScript in dist. This separates code you write from code generated by the compiler.
Framework projects may use a different structure, but the same idea applies: source code should be organized clearly, and generated output should not be edited by hand.
my-typescript-app/
package.json
tsconfig.json
src/
app.ts
dist/
app.js
Modern editors such as Visual Studio Code understand TypeScript very well. You get autocomplete, inline errors, refactoring tools, go-to-definition, and hover information without much extra setup.
The best workflow is to let TypeScript guide you while you type. Do not wait until the end of a feature to run the compiler. The earlier you respond to type errors, the easier they are to fix.
Start small: create one TypeScript file, compile it, run the generated JavaScript, then add tsconfig.json. After that, move into functions, arrays, objects, unions, and interfaces.
This workflow gives you a clear mental model. TypeScript checks the code. JavaScript runs the code. The compiler configuration connects the project together.
npx tsc to run the local TypeScript compiler.
tsconfig.json controls project-wide compiler behavior.
src and dist structure keeps source and output separate.
Explore 500+ free tutorials across 20+ languages and frameworks.