Notes On ...

TypeScript

let someString: string = "This is TypeScript";
let someNumber: number = 324;
let someBool: boolean;

function helloWorld() {
  console.log(someString);
}

helloWorld()

TypeScript is a strongly typed programming language that builds on JavaScript 🗒️. It is a strict superset of JavaScript, meaning that you can write plain JavaScript in a .ts file, and the extra features of TypeScript are completely optional. This is because TypeScript acts like a compiled language, that eventually compiles into regular old JavaScript.

Advantages

Compiler

The TypeScript compiler, tsc, can be configured by modifying the tsconfig.json.

A simple, default config can be generated by running:

tsc --init

which contains several options commented out.

Without a tsconfig.json file, you must include the filename to compile:

tsc someFile.ts

however, if a tsconfig.json exists in the path, simply running:

tsc

will automatically compile any typescript files.

Watch Flag

tsc -w

Passing the -w flag when calling the compiler, will allow tsc to “watch” for any changes, and automatically compile in the background. Alternatively, you can add:

{
  "compilerOptions": {
    "watch": true
  }
}

to your tsconfig.json to do the same.