Install VSCode

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


Install Node

Download and install the Node package from https://nodejs.org/en/download


Create a Folder for our Project

mkdir tsSample
cd tsSample

Create a Node Package (package.json)

npm init -y

This command creates a package file called package.json


package.json
{
  "name": "tssample",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

Install Typescript

Using node, you can install typescript by issuing the following command:

sudo npm install -g typescript

After installing typescript, you have access to tsc, the typescript compiler command line tool.

Install Typescript Node

Typescript Node is used to debug TypeScript.

sudo npm install -g ts-node

Because of a bug, you may need to install it locally as well

npm install ts-node --save-dev


Install TypeScript Debugger in VSCode


Initialize TypeScript Config

Initialize a new project while specifying the output directories. The sourceMap flag keeps a map of the source to the compiled javascript file.

tsc --init --sourceMap --outDir dist

This command create a typescript configuration file called: tsconfig.json.


Create Directories and Source

Make outDir.

mkdir dist


Testing

Mocha

Mocha is a unit test framework for TypeScript.

https://www.testim.io/blog/mocha-for-typescript-testing/


sudo npm install -g mocha --save-dev
npm install mocha --save-dev


Verify it is installed correctly

mocha --version                     
11.1.0



To install types associated with Chai, run the following command:

npm install @types/mocha --save-dev
npm install chai @types/chai@4.2.0 --save-dev
npm install sinon @types/sinon --save-dev


npm run build
npm test




References

ReferenceURL
THIS is EASY TypeScript Setup in VSCodehttps://www.youtube.com/watch?v=4zdBk6wisxc
Mocha for TypeScript Testing: How to Get Startedhttps://www.testim.io/blog/mocha-for-typescript-testing/
  • No labels