When I was a child, I used to play construction with my Dad’s music cassette collection. Sometimes, I would mix up the cases and the cassettes inside for fun. When my Dad wanted to listen to the music he liked, he would be disturbed when a completely different song play. And he would be frustrated when he couldn’t find the real one.
If I had the magic lamp, I would ask Genie Smith to find me a way to designate types to data & objects when I write code and not when I execute it. And he would’ve said “Dude you can use TypeScript. It has what you need”.
If you don’t know what TypeScript is, it is an open source programming language designed to provide type-safety to JS projects with its strict type system.
After learning typescript for a week, here are my thoughts on TypeScript.
I feel that typescript is like a bouncer in a bar who push away people when they do not follow the party etiquettes. It’s because TS pushes me back whenever there is an inadvertent type-related error until I fix it. It might seem tedious, It’s helpful nonetheless. The TS compiler helped me prevent spending a lot of time to debug the error which is the case in JS.
My favourite part of typescript is its ability to present hints while I code. When combined with powerful code editors like VS Code or Atom, the contextual code suggestions helped me reduce errors and increased my typing speed. TS can do this because it’s a statically typed language. It means information about types are available to the compiler before the compilation starts. This availability of information helps the editors compile my code on the go and provide contextual suggestions.
Available separately the linter when enabled in the editor, can detect errors of syntactic, type and even contextual nature. It presents the errors by underlining the error part with red squiggly lines as I type. This makes error correction easier and faster
New nifty features in typescript like the call signatures, object structure definition and interfaces allow me to plan ahead on how I’ll be applying my design to the code. For example, the call signatures are similar to function declaration in C allow me to sketch out the number of parameters needed and the return type. And the Object structure definition allows me to design a skeleton for an object before I define it.
What makes typescript versatile is its wide variety of configuration options. I can enable and disable different options to cater to my project’s needs.
One of the settings I used a lot is the target option. It flipped between commonJS module system and the es5 module system while learning.
TS has just too many configuration options for a beginner. The ignorance of the purpose of some of these options led me to trouble. I did not know I had to include a separate library to use the DOM functions. I was like “What do you mean getElementById is not defined?”
What makes typescript great is, it allows programmers to define new types for their need. Making use of this feature the definitely.org community has created high-quality type definitions for popular JS frameworks like JQuery, node.js and Angular which allows the use of these frameworks in Typescript.
But, could not find enough information on how to use a JS plugin or framework if it is not supported by the definitely typed community.
Typescript has so many features that I found useful. But in terms of documentation, it is partial to node.js. I found lots of learning aids about TS for node.js. But I couldn’t find equivalent amounts of learning aids for front end programming.