How to debug typescript code alone without converting into JavaScript
- Create the folder. Go inside the folder. Go to the terminal or command prompt.
- Run
npm init --yes
that will create default setting for your typescript app. - Run
npm i -D typescript
this will install the typescript in your project without installing globally in your computer. - Run
npx tsc --version
to check the typescript. - Run
npx tsc --init
to create the 'tsconfig.json' file with default option. - Add the
"lib": ["ES6", "DOM"],
in 'tsconfig.json'. if you won't add "ES6" then you might get an error "Cannot find global type 'Array'." - Run
npm i -D ts-node
. - Now add the "singly-linked-list.ts" and "linked-list.ts" file inside the 'src/' folder.
- Run the command
npx ts-node ./src/linked-list.ts
you will see the result in console. - Now if we want to debug same code just add the
launch.json
in .vscode/ folder.
{
"version": "0.2.0",
"configurations": [
{
"name": "Current TS Tests File",
"type": "node",
"request": "launch",
"args": ["-r", "ts-node/register", "${relativeFile}"],
"cwd": "${workspaceRoot}",
"runtimeExecutable": "/Users/anuragsharma/.nvm/versions/node/v14.21.3/bin/node",
},
]
}