typescriptgoogle-apps-scriptcommonjsclasp

Use Typescript with Google Apps Script


I'd like to use Typescript for my Google Apps Script (GAS) projects, but I can't find a way to compile my code into something that GAS accepts.

GAS doesn't support export, and Typescript seems to dislike accessing variables via the global scope (it wants imports/require, and thus exports).

I'm looking for any of the following solutions which I believe would make things work for me:

1) Babel plugin or the like that can remove all the Import and Export statements along with their attributed names (requires that I don't use the same method names, which I don't.

So:

import MyLibrary from './library';
export function greetJohn() { MyLibrary.greet('John'); }
export default { greetJohn }

Becomes:

function greetJohn() { greet('John'); }

2) Change typescript so that it can see the global scope

3) Babel plugin or the like that combines all the .ts files into one .js file and transforms the import/export statements by treating each file like an Object/function.


Solution

  • Now it's possible to use Typescript to develop Google Apps Script projects but this could not be done directly on the Apps Script Editor.

    According to Develop Apps Script using TypeScript the easier way is by using clasp.

    Related