Getting started with TypeScript in Visual Studio Code

Some instructions that distill how one may get started with using TypeScript in Visual Studio Code. Step 1: Set up your development environment Download and run the installer for Visual Studio Code from the following link: https://code.visualstudio.com/download Step 2: Install node.js Download and run the installer for node.js from the following link: https://nodejs.org/ Step 3: Install TypeScript Once node.js has been installed you can install TypeScript. Close VS Code if opened and open a command prompt and run the command: [code language="xml"] npm install -g typescript [/code] (Use the -g to ensure typescript is installed globally, not just for the folder you are in.) Step 4: Set up an example project Open VS Code. Create a new Terminal by selecting Terminal > New Terminal. Create a directory for your project using the mkdir command and navigate to that folder: Close the terminal and open the folder you just created by selecting File > Open Folder: Step 5: Create a new typescript.json file Run the command: [code language="xml"] tsc --init [/code] Alternatively you can create your own tsconfig.json file: [code language="xml"] { "compilerOptions": { "target": "es5", "module": "commonjs", "sourceMap": true } } [/code] Step 6: Create and transpile example helloworld.ts code: [code language="xml"] let message : string = "Hello World"; console.log(message); [/code] Compile it using the terminal command: [code language="xml"] tsc helloworld.tsc [/code] This will generate the file helloworld.js: [code language="xml"] var message = "Hello World"; console.log(message); [/code] Step 7: Make TypeScript automatically look for and transpile your changes Select Ctrl + Shift + B Select tsc:build: This will automatically trigger the transpilation of ts to js files each time the ts file is changed.

Comments

Popular posts from this blog

Using the Supervisor Controller Pattern to access View controls in MVVM

Getting started with client-server applications in C++

How to send an e-mail via Google SMTP using C#