What is TypeScript?
Defining variable types
One of the biggest differences with typescript is that it’s a strongly typed language meaning that it has stricter typing rules requiring things like semicolons and a consistent data type for your variables. Below is an example of how this enables you to declare the types of your variables.
`age = 45`
`age: number = 45;`
Also fine is
`age = 45;`
The benefit of this is that the data type can be clearly defined and can help you determine what the variable is. Imagine you have a variable that returns a result from a backend API request and isn’t defined until the call.
Static type checking
TypeScript can also warn you of errors before you have even compiled the project. In the below example I have declared an array called numbers and then tried to log something called hello which doesn’t exist and then TypeScript will tell me that this doesn’t exist.
For me, this singular reason is enough to choose TypeScript because this one feature could save you a lot of headaches as the system gets bigger and it becomes increasingly more difficult to locate problems like this. If you had a very large application you could accidentally use the same variable for the same thing and change data types. An example of this could be where someone wanted to use numbers to store a single integer and then someone else uses it to store an array of integers. With typescript you’ll get warned of this mismatch before you deploy the code giving you plenty of time to sort out your errors.
Coming from another strictly typed language?
To end things off
Tom is an apprentice APL developer. He was born in Haywards Heath and has grown up in Southwater. At college he studied I.T, Media Studies and Sport BTEC where he realised that he was interested in software. After finishing college he started his career as a Mobile Application Tester before moving into an apprenticeship in software development. More about Tom
Ask Tom about Software Solutions