Typescript intro

Typescript receives universal praise on my twitter feed so I though I would spend some time checking it out. Developed and maintained by Microsoft I’m very curious to find out why people prefer it so much over JS when as a newbie it looks just like JS. TLDR it provides a lot of ‘traditional’ features.

You will need to install the TypeScript compiler either globally or in your workspace to transpile TypeScript source code to JavaScript (tsc HelloWorld.ts).

This helpful FCC article (link) tries to answer these questions:

  • How can I add types to my JavaScript project?
  • What is TypeScript?
  • How can I use TypeScript in a JavaScript project?
  • What are the steps to convert a JavaScript application to support TypeScript?
  • How can I take care of build & packaging?
  • How can I take care of linting?
  • How can I “sell” TypeScript to my organization and developers?

A summary of the fundamentals I’ve learnt so far would be:

  • It’s a superset of JavaScript, meaning that any valid JavaScript code will also run as expected in TypeScript.
  • It needs to be compiled to plain JavaScript during runtime, therefore a compiler is needed to get back the JS Code.
  • TypeScript uses static typing, meaning that you can give a type to a variable during declaration.
  • tsconfig is a JSON file that helps to configure TypeScript. Having a config file is better since it helps to control the behavior of the compiler.
  • TypeScript has several types such as number, string, boolean, enum, void, null, undefined, any, never, array, and tuple.

Other good resources that have helped my understanding of it are: