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 !
Top comments (4)
You can use code blocks to format json
ok updating .. thx
Use markdown, please π.
sure thx