Learning Outcome
What I learnt today
I learnt a bit of typescript as I paired with my Mentor on refactoring a Retirement calculator Kata I had previously written in purely Javascript to use some typescript code.
So what is Typescript?
By definition, “TypeScript is JavaScript for application-scale development.” TypeScript is a strongly typed, object oriented, compiled language. It was designed by Anders Hejlsberg at Microsoft. TypeScript is both a language and a set of tools. TypeScript is a typed superset of JavaScript compiled to JavaScript. In other words, TypeScript is JavaScript plus some additional features. (Excerpt Tutorial Point)
Typescript performs static type validation.
So then: Do I need to validate everything? Simply, No
Checking all the variables of my application is time-consuming from a development and performance perspective.
Example:
Migrating my logic from Javascript to Typescript, I setup a config file in the root director of my project named tsconfig.json
, this is for managing my project’s options, such as which files I want to include, and what sorts of checking I want to perform.
I modified my file extension to .ts from .js. At this point, I ran tsc
at the root of my project, I could see output files in the built
directory. The layout of files in built
looks identical to the layout of lib
. I now have TypeScript working with my project.
This is how my constructor logic now looks like after refactoring