Starting out with TypeScript

Why am I learning TypeScript?

I have been working with the Microsoft Tech Stack for the last 20 years. Specifically in the .NET and C# space. But two years ago, I started writing JavaScript in the back end. Specifically on the Google Scripts Platform (GSP).

Google Scripts Platform

I have been playing around with the Google Scripts Platform (GSP) both at home, for my parish during COVID lockdowns and at work. With the power of collecting data via Google Forms, storing data in Google Sheets and visualising data in either Google Sheets or Docs or even exported PDFs, GSP is pretty powerful. I wrote quite a bit of JavaScript to automate so many things. (Maybe I will blog about them gradually with some useful code snippets in the future.)

Why TypeScript?

So after writing C# for around 20 years, why did I want to learn TypeScript?

  • Write JavaScript code that compiles
  • Build and share some nifty GCP utilities
  • Build a static website with Next.js
  • Build a static website with Gatsby

The Transition

This is how I started on my journey from C# to JavaScript to TypeScript.

JavaScript to TypeScript

Coming from a very OOP (Object Oriented Programming) background, writing code in JavaScript felt a bit dirty. Don't get me wrong - JavaScript is a pretty powerful language and how it works on GSP is terrific. But I missed the strict types and compile-time error-checking capabilities of C#.

I heard about TypeScript a long time ago, but that was people complaining about how hard it was. But in recent times, that sentiment has changed and developers want to work with TypeScript.

TypeScript turned 10 years old as I completed learning the basics of it. I started off with learning TypeScript coming from a C# background and then moved on to the TypeScript Handbook.

I would recommend going through the handbook from end to end to grasp the concepts and the differences from other languages such as C#. Variable scoping and function overloading were a few things that I learnt along the way that were completely different from other programming languages I have used.

TypeScript in Practice

Once set up properly, the intellisense in an IDE (Integrated Development Environment) like Visual Studio Code makes writing and compiling TypeScript a breeze. In addition, using a unit testing framework such as Jest makes your code so much more robust.

Next steps

I want to quickly utilise TypeScript in frameworks like NextJS and Gatsby. But I wanted to complete something useful for others and utilise my newly acquired TypeScript knowledge before I went there. So you will see a few nifty little utilities I wrote on GSP with JavaScript converted to TypeScript.

You will also see some weird errors/issues (and my fixes to those) as I encounter them.

Wish me luck and let's see how I go!