Search code examples
javascripttypescriptgoogle-apps-scriptclasp

Annotate variable with Google Script type in TypeScript file (using clasp)


I'm writing a Google Apps Script (GAS) using the clasp tool, which lets you locally develop TypeScript files that compile to Google Scripts.

I imported Google Script type definitions by running npm i -S @types/google-apps-script, and my IDE (VS Code) does indeed seem to understand the Google Script types. I cannot, however, seem to annotate my variables with these type definition. For example,

let ss: Spreadsheet;
ss = SpreadsheetApp.getActive();

Is this possible to annotate my code with these imported type definitions?


Solution

  • Custom type annotations can be used like this:

    var ss: GoogleAppsScript.Spreadsheet.Spreadsheet;
    
    • namespace: GoogleAppsScript
    • module: Spreadsheet
    • interface: Spreadsheet