Part 1: TypeScript Overview
Last updated
Last updated
TypeScript is an open-source programming language developed by Microsoft. It is a superset of JavaScript that is strictly-typed. The TypeScript file is then converted into a JavaScript file by the TypeScript complier.
So, what is a strictly-typed language? A strictly-typed language is one where data types HAVE to be defined by the programmer. With JavaScript, a variable can hold multiple types of data. This means a variable can hold a string, an integer, an array, an object, etc. You could start with a variable that is storing an integer, and then reset it to hold a string in the next line. That would not cause an error.
However, with a strictly-type language the example above WOULD cause an error. Why would that happen? This is due to the variable intially being set to hold an integer. Trying to switch data types afterwards would throw an error during compilation.
What would be the advantages of using this type of programming language, especially after using a loosely-typed language?
Explicit in intent - This allows the programmer to know exactly what type of input to use and what kind of output to expect.
Error prevention during compilation - This is also considered failing fast. Since the code won't run, the error can be corrected quickly. With a loosely-typed language, you won't be alerted to type errors before it appears during run time. Correcting that error could take time to solve, since it might not be apparent that it was caused by incorrect data types.
adapted from Wikipedia and Loud Thinking by David Heinemeier Hansson