

Having a config file is better since it helps control the behavior of the compiler.

Tsconfig is a JSON file that helps configure TypeScript. It's not mandatory to add a config file - but for many cases, it's useful to have it since it allows us to define rulesets for the compiler. Later we will dive into it and what it does, but for now let's add a configuration file to our project. Note that here I use the -g flag to install TypeScript globally so that I can access it from anywhere.īy installing TypeScript, we have now access to the compiler, and we can compile our code to JavaScript. Or if you are using npm: npm install -g typescript And to have access to that tool, you need to install TypeScript by running this command on the terminal. So we need to use a tool to do the compilation. Setting up TypeScriptĪs I said earlier, TypeScript needs to compile to plain JavaScript. Now, let's start using TypeScript in the next section to see it in action. And if the variable has no value, the type will be set to any by default. If no type is defined but the variable has a value, TypeScript will infer the value as type. However, the error does not block the code from executing (and the JavaScript code will still be generated). Static type checking makes TypeScript great because it helps to throw an error at compile-time if the variable is unused or reassigned with a different type annotation. And it's something that can't be done with JavaScript because it's a dynamically typed language – it does not know the data type of a variable until it assigns a value to that variable at runtime. TypeScript uses static typing, meaning that you can give a type to a variable during declaration. It needs to be compiled to plain JavaScript during runtime, therefore you need a compiler to get back the JS Code. TypeScript has all of the functionality of JavaScript as well as some additional features. It's a superset of JavaScript, meaning that any valid JavaScript code will also run as expected in TypeScript. TypeScript is an object-oriented programming language developed and maintained by Microsoft.


TypeScript helps to enhance code quality and understandability, especially with a large codebase. It offers more control over your code since it uses type annotations, interfaces, classes, and static type checking to throw errors at compile-time. TypeScript is a superset that needs to compile to plain JavaScript.
