DEV Community

Prem Jethwa
Prem Jethwa

Posted on • Updated on

3 steps for setting a typescript project? [typescript setup]


How to setup typescript

What is typescript?

A free and open source programming language created and maintained by Microsoft, TypeScript (https://www.typescriptlang.org).

It adds types and more to JavaScript.Types can be added gradually. Specifying more types allows TypeScript to detect more errors.

1 - Install: -

Node.js
Code Editor (VS code recommended)
Install TypeScript (install -g typescript)

2 - Initialize the project: -

Create Project folder
Init ( npx tsc –init )

3 - ProjectName(root directory)/tsconfig.json
-- Open & Setup

{
   "compilerOptions":{
      "target":"es5",
      "module":"commonjs",
      "strict":true
   }
}
Enter fullscreen mode Exit fullscreen mode

There will be many commented out default configurations. This configuration defines the version of JavaScript your TypeScript will be compiled into and the module system for your compiled program. When "strict" is set to true, a wide range of type-checking rules are enabled. As a result, your TypeScript program will have fewer errors.

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    _**"outDir": "dist",
    "sourceMap": true**_
  }
}
Enter fullscreen mode Exit fullscreen mode

When the value of"outDir"is set to "dist", a directory named dist will be created. The compiled JavaScript file will be placed in the dist file when you use npx tsc to compile your TypeScript file.

Setting "sourceMap" to true will allow you to quickly solve errors in the original TypeScript file.

Make sure you save file with .ts extention
Ready to write typescript Code !

Discussion (4)

Collapse
lyrod profile image
Lyrod

You can use code blocks to format json

Collapse
premjethwa profile image
Prem Jethwa Author

ok updating .. thx

Collapse
jancizmar profile image
Jan Cizmar

Use markdown, please πŸ™.

Collapse
premjethwa profile image
Prem Jethwa Author

sure thx