Beginners guide – Typescript in visual studio code

In this post, we will be executing a typescript file in VS Code

Prerequisites

Nodejs & npm

Follow Install & verify nodejs on windows

TypeScript

Start > Run > cmd, type npm install -g typescript

to verify, on cmd, type tsc -v

Visual Studio Code

Download and install fromĀ https://code.visualstudio.com/download

Steps to write typescript sample code in vs code

Create a folder TypeScript under C:\ drive.

Open VS code, Select File > Open Folder.. and chose c:\TypeScript (1)

(2) – Create a file

(3) – Create a folder



test.ts

Let’s create a testscript file with filename test.ts [under TypeScript folder, as shown above screenshot]

Note – Typescript is superset of java script [with some improvements]

x & y are numeric variables, so represented as x : number

constructor() is same as Add() – same name as class name or just contructor

let is a typescript variable declaration type [as we have var in JS but with some improvements]

Refer let for more information.

semicolon at end of code statements are optional

test.ts compiles back to test.js and then executes the code

tasks.json

Key press F1 or Ctrl + Shift + P and type configure task runner

this will create another file tasks.json

launch.json

To debug the code in VS code, we need launch.json

tsconfig.json

Arrange these 3 files as shown above screenshot

Now to debug or run the .ts file, key press F5

You will see the output under Debug Console [View > Debug Console]

ReferĀ https://code.visualstudio.com/docs/editor/debugging for debugging options.

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: