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

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 TypeS…


This content originally appeared on DEV Community and was authored by prem jethwa

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
}
}

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

}
}

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 !


This content originally appeared on DEV Community and was authored by prem jethwa


Print Share Comment Cite Upload Translate Updates
APA

prem jethwa | Sciencx (2022-01-12T07:19:33+00:00) 3 steps for setting a typescript project? [typescript setup]. Retrieved from https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/

MLA
" » 3 steps for setting a typescript project? [typescript setup]." prem jethwa | Sciencx - Wednesday January 12, 2022, https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/
HARVARD
prem jethwa | Sciencx Wednesday January 12, 2022 » 3 steps for setting a typescript project? [typescript setup]., viewed ,<https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/>
VANCOUVER
prem jethwa | Sciencx - » 3 steps for setting a typescript project? [typescript setup]. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/
CHICAGO
" » 3 steps for setting a typescript project? [typescript setup]." prem jethwa | Sciencx - Accessed . https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/
IEEE
" » 3 steps for setting a typescript project? [typescript setup]." prem jethwa | Sciencx [Online]. Available: https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/. [Accessed: ]
rf:citation
» 3 steps for setting a typescript project? [typescript setup] | prem jethwa | Sciencx | https://www.scien.cx/2022/01/12/3-steps-for-setting-a-typescript-project-typescript-setup/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.