Snippets

    Includes Google App Script (gscript)

    Exhaustive Matching πŸ”—

    Source: https://www.typescriptlang.org/docs/handbook/2/narrowing.html#exhaustiveness-checking

    type Shape = Circle | Square;
    
    function getArea(shape: Shape) {
      switch (shape.kind) {
        case "circle":
          return Math.PI * shape.radius ** 2;
        case "square":
          return shape.sideLength ** 2;
        default:
          const _exhaustiveCheck: never = shape;
          return _exhaustiveCheck;
      }
    }
    

    Sleep in Google App Script (gscript) πŸ”—

    Source: https://developers.google.com/apps-script/reference/utilities/utilities#sleepmilliseconds

    Utilities.sleep(milliseconds);
    

    Google Script Simple Trigger πŸ”—

    On Open πŸ”—

    Putting it at the top outside of the namespace in shared.ts is the convention in use

    function onOpen() {
        const menu = SpreadsheetApp.getUi().createMenu('Scripts');
        menu.addItem('Displayed Text', 'functionName').addToUi();
        menu.addItem('Button 2', 'functionName2').addToUi();
    }
    

    On Edit πŸ”—

    function onEditBody(e: GoogleAppsScript.Events.SheetsOnEdit) {
            if (
                (e.range.getColumn() !== OUTPUT_COL_DATE) &&
                (e.range.getColumn() !== OUTPUT_COL_TIME_START) &&
                (e.range.getColumn() !== OUTPUT_COL_TIME_END) &&
                (e.range.getWidth() === 1) &&
                (e.range.getHeight() === 1)) {
                // Do the needful (note variables on rhs above are not automatically defined)
            }
        }