Skip to content

2. Setting Up a Work Environment

The original document (2019) provided a detailed explanation of how to install [Laragon], [Netbeans], and [Visual Studio Code] on Windows 10, with numerous screenshots illustrating the configuration of PATH. In 2026, the installation is much simpler: we will use the following tools.

  • [Visual Studio Code] to generate the TypeScript code;
  • [Node.js], version 26 or later—this is the version that made the [Temporal] object, presented in the last chapter of this document, available without any special options;
  • [TypeScript], version 6;
  • [tsx], a tool that runs a .ts file directly without a prior compilation step—this is what we will use for all the scripts in this document;
  • [npm] (Node Package Manager), included with Node.js, to install the libraries we’ll need;

2.1. Verifying the Installed Tools

Once Node.js and Visual Studio Code are installed, open a terminal (either within VSCode or outside of it) and verify the installed versions:

node --version

Result (the exact version may vary; 26.x or higher is recommended for this course):

v22.22.2
npx tsc --version

Execution result:

Version 6.0.3

2.2. Setting up the VSCode project

The code folder for this course is as follows:

Image

This folder corresponds to the complete script directory structure (cours-typescript-nestjs-scripts/) presented in the introduction to this document, which you have downloaded. Open the typescript-fundamentals/ subfolder in VSCode: this is where the scripts for the first chapters of this course are located. It already contains, at its root, the two files package.json and tsconfig.json—let’s take a look at them.

2.2.1. The file package.json

This file lists the project’s dependencies. It also specifies "type": "module", so that Node.js natively treats our files as ECMAScript modules (with import/export), without needing an intermediary tool as was the case in 2019 with the esm package.

{
  "type": "module",
  "scripts": {
    "check": "tsc --noEmit"
  },
  "devDependencies": {
    "eslint": "^8.57.0",
    "@typescript-eslint/eslint-plugin": "^7.18.0",
    "@typescript-eslint/parser": "^7.18.0",
    "typescript": "^6.0.3",
    "tsx": "^4.19.0",
    "@types/node": "^22.7.0"
  },
  "dependencies": {
    "axios": "^1.7.0",
    "moment": "^2.30.0",
    "qs": "^6.12.0",
    "sprintf-js": "^1.1.3"
  }
}

2.2.2. The tsconfig.json file

This file configures the TypeScript compiler. Strict mode is enabled: this is the recommended configuration, as it allows TypeScript to detect as many errors as possible during compilation.

{
  "compilerOptions": {
    "target": "ES2023",
    "lib": ["ESNext"],
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "strict": true,
    "types": ["node"],
    "noEmit": true
  },
  "include": ["**/*.ts"]
}
Important: Starting with TypeScript 6.0, the "types" line: ["node"] is essential: without it, TypeScript no longer automatically recognizes Node.js global objects such as `console` or `process`, unlike versions prior to 6.0.
Note: There is nothing to install here. As with all other folders in the directory tree, the dependencies for `typescript-fundamentals/`—and for all the scripts in this course—have already been installed by a single `npm install` command, run once at the root of `cours-typescript-nestjs-scripts/` (see the introduction to this document): This is shown by the node_modules folder already present at the root in the screenshot above, thanks to [npm workspaces]. The project is therefore ready to use as soon as you download it.

If you haven’t downloaded the directory structure yet, or if you need to reinstall its dependencies, here’s a reminder of the single command to run—just once—at the root directory; it will install all the Node.js modules required for all the course scripts:

npm install

The following commands are entered in a VSCode terminal with the directory set to [typescript-fondamentaux].

Image

2.3. First script

Let’s create a file named tests/test-01.ts:

// A First Program TypeScript
console.log("hello world!");

Run it from the terminal, in the project root directory:

npx tsx tests/test-01.ts

Execution result:

hello world!

2.4. Second script: type checking

Let’s create a second file, tests/test-02.ts, with an explicitly typed variable:

'use strict'
let x: number = 4;
console.log("x=", x);
npx tsx tests/test-02.ts

Execution result:

x= 4

Now let's try assigning a string to this variable declared as a number:

x = "abc";

Without even running the script, VSCode immediately highlights the line in red, and the type-checking command fails:

npx tsc --noEmit

Execution result:

tests/test-02.ts(4,1): error TS2322: Type 'string' is not assignable to type 'number'.

This is the key advantage of TypeScript over JavaScript: an entire category of errors (accidental type mixing) is detected before execution, directly in the editor, rather than discovered when the code crashes in production.

2.5. ESLint

[ESLint] is a tool that verifies that the code adheres to a set of style rules and best practices (unused variables, suspicious comparisons, etc.). The configuration file .eslintrc.cjs (the .cjs extension, not .js, is required because package.json declares "type": "module") uses the @typescript-eslint parser, which understands the TypeScript syntax (types, interfaces, private fields #x...):

module.exports = {
  root: true,
  env: { node: true, es2024: true },
  extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
  parser: "@typescript-eslint/parser",
  plugins: ["@typescript-eslint"],
  parserOptions: { ecmaVersion: "latest", sourceType: "module" }
};

We then analyze the entire project using:

npx eslint . --ext .ts

2.6. VSCode ESLint

The VSCode extension, named [ESLint] (to be installed from the Extensions tab), displays ESLint warnings directly in the editor in real time—without having to run the command manually each time.

We now have a complete working environment. The next chapter covers the basics of the TypeScript language.