How to Install TypeScript: Getting Started with Your First Project - Beginner Tips
Setting up TypeScript is straightforward and takes just a few steps. Here's how you can get started
Step 1: Install TypeScript
TypeScript is installed via npm, the Node.js package manager. If you don’t have Node.js installed, download and install it first from Node.js official site.
Then, install TypeScript globally by running:
npm install -g typescriptVerify the installation by checking the version:
tsc --versionThis command will output the installed TypeScript version.
Step 2: Set Up a New Project
Create a Project Folder:
mkdir my-typescript-project
cd my-typescript-projectInitialize a New npm Project:
This creates apackage.jsonfile to manage dependencies.
npm init -yInstall TypeScript Locally (optional):
For project-specific use, add TypeScript as a dependency:
npm install --save-dev typescriptStep 3: Create a tsconfig.json
TypeScript uses tsconfig.json to define project settings. Generate it with:
tsc --initThis creates a file with default options like:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"strict": true,
"outDir": "./dist",
"rootDir": "./src"
}
}Step 4: Write Your First TypeScript File
Create a
srcfolder and a file namedindex.ts:
mkdir src
echo 'console.log("Hello, TypeScript!");' > src/index.tsCompile the file to JavaScript using:
tscBy default, TypeScript compiles the file and places the output in a
distfolder (based ontsconfig.json).
Step 5: Run the Compiled JavaScript
Execute the compiled file using Node.js:
node dist/index.jsCongratulations! 🎉
You’ve set up your first TypeScript project! Next steps include exploring type annotations, configuring strict options, and diving into more advanced features.

