Setup a TypeScript Project Fast
Create a New Project in 30 seconds!
Learn how to install TypeScript and run your first file!
This article will guide you through setting up a TypeScript project, allowing you to start reaping these benefits immediately and testing out TypeScript today.
1) Initialize Your Project
Let's create a new directory for our project and initialize it with npm:
mkdir typescript-project cd typescript-project npm init -y
-y flag (on npm init) accepts all the default setup options for the npm project setup.
2) Install TypeScript
We can add TypeScript as a development dependency to our project by using the following command:
npm install typescript --save-dev
3) Create a TypeScript Configuration File
You need a special configuration file named
tsconfig.json file in a directory that indicates that the directory is the root of a TypeScript project.
We can generate it easily with some good defaults with the following command:
npx tsc --init
Create your first TS file
You can start writing TypeScript!
Create a new file in your project called
index.ts (don't forget the extension is
ts for TypeScript).
Optional: Run your script
To run your script, let's add one more package called
npm install ts-node --save-dev
Now that it's installed, we can run the following command to run our
node --loader ts-node/esm index.ts
Optional: Compiling your TS
If you want to compile your files automatically, run the command with the
--watch flag. Here's the full command:
npx tsc --watch
🚨 Want to make friends and learn from peers? You can join our free web developer community here. 🎉