Learning TypeScript: Part 1

Hello all!

This is my first post to Dev.to and I am very excited for this to be the beginning of my TypeScript series where I will be documenting what I am learning through Codecademy and Free Code Camp. I will not just be copying and pastin…


This content originally appeared on DEV Community and was authored by 🦾Jack Madden🦾

Hello all!

This is my first post to Dev.to and I am very excited for this to be the beginning of my TypeScript series where I will be documenting what I am learning through Codecademy and Free Code Camp. I will not just be copying and pasting the information, but learning, and bringing it to you in a concise manner. Please enjoy and don't be timid to send me a message of what you think!

                         LETTUCE BEGIN🥬

Alt TS-logo

How TypeScript Works

TypeScript is a superset of Javascript, invented by Microsoft, that adds strong type checking. Hence, the 'type' in TypeScript, I guess. The TS code is taken into a compiler and then translated into JS code, meaning all of the features of JS are available to us, plus the added features of TS.

Some added features are such as better development-time tooling (the amount of time from work started to work delivered), static code analysis (analysis of the code without launching code), and compile-time type checking (making sure all the types are used as they should be).

If you are coming into this with some Javascript knowledge, already, then that is preferred because TS sometimes looks roughly the same as JS code! TS files are stored in .ts files, compared to JS files being stored in .js files, so don't get that mixed up, ya hear?

When To Use TypeScript

Large Codebase

When to use a specific language, library, or framework can definitely be tricky. The same goes for TS, as there are many times where it is best to use, but also times where it may not be most practical. From what I gather, TS is getting such a big following in the Javascript community because it cuts down on common errors. However, if your codebase is not going to be large to begin with, there really isn't much reason to convert your JS files to TS, as sometimes it will add about 30% to the total size of the code

Accustomed to Type Languages

That's pretty vague and self-explanatory, right? If you or your team wants to use it, then use it. Sure? I can't judge because I had learned React a little while back and now I try to work it into every project I can.

There are also some other type-strict languages out there that keep the same mindset as TS, such as C#. While they are based on much different languages, the same person that created TS is also the same person that created C#. I guess you could say they have a TYPE 😏.

Library or Framework Wants TS

I personally have never ran into this sort of request from a library or framework, but it is definitely not too far out of the ordinary. It seems that for TS, Angular 2 seems to be really screaming for the necessity of it. So if you are reading through the documentation of a library or framework and it is begging you to use TS, be my guest.

Type Demanding Situations

It makes sense that there would be some situations where having a strict type is crucial for your app or code snippet. One that pops into my mind is anything having to do with forms. If a rascal of a user tries to input a number into a string situation, that can throw a major error or crash your app if not handled properly. TS acts as some sort of gatekeeper in the way that this is one of the first things that it checks for via the compile-time type-checking we had discussed earlier. If you're expecting to be using a good amount of forms, or a type heavy application, then TS might be the best option.

Conclusion

I can not thank you enough for making it to the end of my first insertion to the Learning TypeScript series! While this article was more based on what TS is, and when to use it, the following articles should jump into some sweet, sweet code that we all know and love. Thank you and look out for the next submission, don't forget to follow me here and on Twitter! Peace!


This content originally appeared on DEV Community and was authored by 🦾Jack Madden🦾


Print Share Comment Cite Upload Translate Updates
APA

🦾Jack Madden🦾 | Sciencx (2021-10-02T16:50:10+00:00) Learning TypeScript: Part 1. Retrieved from https://www.scien.cx/2021/10/02/learning-typescript-part-1/

MLA
" » Learning TypeScript: Part 1." 🦾Jack Madden🦾 | Sciencx - Saturday October 2, 2021, https://www.scien.cx/2021/10/02/learning-typescript-part-1/
HARVARD
🦾Jack Madden🦾 | Sciencx Saturday October 2, 2021 » Learning TypeScript: Part 1., viewed ,<https://www.scien.cx/2021/10/02/learning-typescript-part-1/>
VANCOUVER
🦾Jack Madden🦾 | Sciencx - » Learning TypeScript: Part 1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/02/learning-typescript-part-1/
CHICAGO
" » Learning TypeScript: Part 1." 🦾Jack Madden🦾 | Sciencx - Accessed . https://www.scien.cx/2021/10/02/learning-typescript-part-1/
IEEE
" » Learning TypeScript: Part 1." 🦾Jack Madden🦾 | Sciencx [Online]. Available: https://www.scien.cx/2021/10/02/learning-typescript-part-1/. [Accessed: ]
rf:citation
» Learning TypeScript: Part 1 | 🦾Jack Madden🦾 | Sciencx | https://www.scien.cx/2021/10/02/learning-typescript-part-1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.