Typescript — The Basics

While doing my job search, I noticed that Typescript was required by many companies. I decided to look into this programming language and I am going to do a resume of what I have learned so far.

What is Typescript?

TypeScript is a programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript and adds optional static typing to the language. TypeScript is designed for the development of large applications and transcompiles to JavaScript.

Why Typescript?

As developers, we are trying to keep our code as DRY as possible to make our code look easier and not type anymore code that we have to, but this is a situation where writing a little bit more code upfront will pay bid dividends as the project grows.

Installing Typescript

First thing to do is to install Typescript globally with npm.

npm i -g typescript
Typescript version used
Creating a TS code
{
"compilerOptions": {
"target": "es3",
"watch": true,
"lib": ["dom", "es2017"]
}
}
  1. The second line is watch that will recompile our code every time we save the file (that will save us from having to run that tsc command after every change).
  2. The next option is LIB which allows us to automatically include typings for certain environments such as the DOM or ES 2017.

Third-party libraries

Install lodash with npm which creates a node modules folder with the source code for lodash and import it in index.ts

npm i lodash
npm i @types/lodash
//index.tsimport * from _ 'lodash'

Conclusion

Using Typescript is a very great way to prevent bug. Airbnb claims 38% of bugs could have been prevented by TypeScript.

French guy who recently moved to the United States. I am also changing career after having worked 13 years in restaurants. I will be going into coding.