keywords: TypeScript, JavaScript Engine, Nodejs, Chrome, V8, Notes

Environment Setup for TypeScript

How to update TypeScript to latest version with npm
npm install -g typescript@latest


yarn global add typescript@latest  // if you use yarn package manager


Setup compilation environment for Visual Studio Code

1, Install compiler (tsc) of TypeScript:

npm install typescript -g

2, Create a directory as your project, named myproj.

3, Create a TypeScript source file under myproj, named hello.ts, and print a message in console:

let message: string = 'Hello';

then compile source with command:

tsc hello.ts​

4, Address to directory myproj in command, then generate tsconfig.json using command:

tsc --init


5, Go to your project directory and excute commands:

npm install typescript --save
npm install ts-node --save-dev


If you got error:

Error: Cannot find module 'typescript'

Go to your project directory and link typescript to the project:

cd myproj

npm link typescript

6, Run npx ts-node to test your source code:

npx ts-node hello.ts


7, Install extension TypeScript Debugger, then click Run -> Add Configuration -> select TS Debug:

8, Open directory myproj in Visual Studio Code, then press F5 or click Run -> Start Debugging.


If you get error on Windows while Start Debugging:

tsc.ps1 cannot be loaded because running scripts is disabled on this system

Excute command using PowerShell as administrator, and select option A(ll):

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned


Now you would run debugging successfully.

Setup compilation environment for Intellij IDEA

Do first five above-side steps, then compile TypeScript source by clicking lable which was in the bottom of editor viewport, then debug your code.

TypeScript plugin is only usable for Intellij IDEA Ultimate Edition and WebStorm.

IntelliJ IDEA Plugins

IntelliJ IDEA (and WebStorm…) plugin to support ‘TypeScript’ as a run configuration


Issue 2:

If you get error while Start Debugging:

D:\SDKs\nodejs\node.exe -r ts-node/register .vscode\launch.json
SyntaxError: D:\myproj\.vscode\launch.json: Unexpected token / in JSON at position 7
    at parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:1128:22)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
Process exited with code 1


Debugger attached.
Waiting for the debugger to disconnect...
let message: string = 'Hello World';

SyntaxError: Unexpected token ':'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
Process exited with code 1

It’s the bug of extentsion TypeScript Debugger of Visual Studio Code.

Recommended to use IntelliJ IDEA intead of Visual Studio Code.

Common API

How to print call stack when error occurs.
try {
   // Code throwing an exception
} catch(e) {


string format
var text = "blah blah";
var strTest = `This is a ${text}`;

String interpolation in Typescript, replacing ‘placeholders’ with variables

Declare variables and export them
export namespace RoleCreationDefine
    const Test01: string = "Neil Wang";
Declare enum and export them
export const enum ESexType {
Declare dictionary and export it

We can try with built-in typescript advanced type called Record<K, T>:

interface MyInterface {
    data: Record<string, Item>;

Put everything together here

interface Item {
    id: string;
    name: string;

interface MyInterface {
    data: Record<string, Item>;

export const obj: MyInterface = {
    data: {
        "123": { id: "123", name: "something" }

Origin: Dictionary type in TypeScript

Frameworks & Libraries

V8 C++ Wrapping

Getting started with embedding V8

Bind C++ functions and classes into V8 JavaScript engine


TypeScriptToLua. Typescript to lua transpiler.

GPU Rendering

A GPU-accelerated computing library for physics simulations and other mathematical calculations



Error on running npm install:

error code EPERM
error syscall open
error path D:\GamesLibrary\EpicGamesStore\UE_4.27\Engine\Source\Programs\PixelStreaming\WebServers\SignallingWebServer\package-lock.json
error errno -4048
error Error: EPERM: operation not permitted, open 'D:\GamesLibrary\EpicGamesStore\UE_4.27\Engine\Source\Programs\PixelStreaming\WebServers\SignallingWebServer\package-lock.json'
error  [Error: EPERM: operation not permitted, open 'D:\GamesLibrary\EpicGamesStore\UE_4.27\Engine\Source\Programs\PixelStreaming\WebServers\SignallingWebServer\package-lock.json'] {
error   errno: -4048,
error   code: 'EPERM',
error   syscall: 'open',
error   path: 'D:\\GamesLibrary\\EpicGamesStore\\UE_4.27\\Engine\\Source\\Programs\\PixelStreaming\\WebServers\\SignallingWebServer\\package-lock.json'
error }
error The operation was rejected by your operating system.
error It's possible that the file was already in use (by a text editor or antivirus),
error or that you lack permissions to access it.
error If you believe this might be a permissions issue, please double-check the
error permissions of the file and its containing directories, or try running
error the command again as root/Administrator.
verbose exit -4048


npm cache clean --force

npm install -g npm@latest --force




Mastering mapped types in TypeScript


Why is TypeScript surpassing Python?


Mastering TypeScript: Build enterprise-ready, modular web applications using TypeScript 4 and modern frameworks, 4th Edition 4th Edition (April 23, 2021)

“As a child I felt myself to be alone, and I am still, because I know things and must hint at things which others apparently know nothing of, and for the most part do not want to know.” ― Carl Gustav Jung, Memories, Dreams, Reflections