Set Up TypeScript in VS CodeThere are two json files that need to get created first. More info can be found TypeScript SetUP in VS Code
tsconfig.jsonThe first step in any new TypeScript project is to add in a tsconfig.json file. This defines the TypeScript project setting such as the compiler options and the files that should be included.
// example
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}
tasks.jsonSet up the task configuration. Open Command Palette with Ctrl + Shift + P and type in Configure Task Runner then select TypeScript - tsconfig.json. This will create a tasks.json file in the workspace .vscode folders.
// example
{
// See http://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": ["-p", "."],
"showOutput": "silent",
"problemMatcher": "$tsc"
}
Build TaskAs this is the only task in the file, you can execute it by simply pressing Ctrl + Shift + B (Run Build Task). Once ran, you’ll see your .js and .js.map files were created in your workspace.
How to RunSimply CTRL + SHIFT + B to build the .ts file and it will generate a .js file and the source map. If it doesn’t build then you probably don’t have the typescript compiler. Just run npm install -g typescript.
Install and Use DT (Definitely Typed)typings
npm install -g typingstypings init. This will create a typings.json and which holds all your DTsjQuery
typings install dt~jquery --save --globalimport the definitely type.import $ from "jquery" or import $ = require("jquery"). Both of these require to reboot the editor.You can also search DTs via typings. e.g. typings search jquery