DEV Community

Bruce Axtens
Bruce Axtens

Posted on • Edited on

4

Typescript and Google Apps Script

Today I learned how to use Typescript. I've got a steadily growing pair of Google Apps Script (GAS) projects and Typescript helped me catch some nasty surprises before they jumped out at me.

It was a simple process too: install the npm modules and set up a couple of configuration files. After that I renamed all my .js to .ts and started putting in type annotations. Pretty soon the "Problems" tab in VSCode started to fill up with notifications. After they were fixed I pushed the code up to Google Sheets and had a look in the online script editor, half expecting a mess. But no mess, just clean ES3 JavaScript.

I was also pleasantly surprised by ts2gas -- code that interposes itself between VSCode and Google Sheets in the clasp pipeline. ts2gas is a "function that transpiles TypeScript to Google Apps Script" and does an exceptional job of it too, including taking ES6 (including classes, let, const and all that) and converting it to the ES3 that GAS (currently) uses.

In my previous postings about javascript I've used Babel to do the conversion to ES3 (for those still stuck on that planet.) Looks like I'll be typescripting and ts2gas-ing them too.

Do be careful with ts2gas. I just bumped into an issue with it's conversion which I have just logged. I've also got a StackOverflow question on a related issue.

Retry later

Top comments (0)

Image of PulumiUP 2025

Transform Your Cloud Infrastructure

Join PulumiUP 2025 on May 6 for Expert Insights & Demos.

Register Now

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay