CLASP

Chester Wyke April 17, 2023 Updated: April 15, 2025 #misc

New project setup

clasp clone <scriptID>

Steps if using TypeScript (TS)

This version is was based on the then version of https://developers.google.com/apps-script/guides/typescript which linked out to https://github.com/google/clasp/blob/master/docs/typescript.md but they no longer provide typescript. See excerpt from the github readme below.

Drop typescript support

Clasp no longer transpiles typescript code. For typescript projects, use typescript with a bundler like Rollup to transform code prior to pushing with clasp.

npm i -S @types/google-apps-script
clasp push --watch

TypeScript Modules, exports and imports

Original Source was: https://github.com/google/clasp/blob/master/docs/typescript.md#the-namespace-statement-workaround but they are dropping typescript support.

Instead of normal imports use the following as import is not supported in GAS

// module.ts
namespace MyLib {
    export function foo() {
    }

    function bar() {
    }  // this function can only be addressed from within the `MyLib` namespace
}
// anyFiles.ts
MyLib.foo();  // address a namespace's exported content directly

Steps if using Javascript (JS)

git submodule add ../js_lib.git

Converting an existing Javascript (JS) project to TypeScript (TS)

Useful Commands

Ignore files

File location

Source: https://github.com/google/clasp#ignore-file-claspignore

Put a .claspignore in the root of the project’s directory. All paths are relative to root.

Format

Uses multimatch

Glob Pattern:

Example

js_lib/**

Installation

Source: https://developers.google.com/apps-script/guides/clasp#installation

First install Install Node.js

npm install @google/clasp -g