Search code examples
typescriptgoogle-apps-scriptv8google-apps-script-runtime

Google Apps Script inheritance on V8


I have recently noticed a weird behaviour of the V8 engine. When inheriting a class found in a separated file, the engine fails to recognise the base class, e.g. the following configuration fails:

BaseFoo.ts

export class BaseFoo {}

SpecialFoo.ts

import { BaseFoo } from "./BaseFoo";

class SpecialFoo extends BaseFoo {}

with an error:

ReferenceError: BaseFoo is not defined [line: 1, function: , file: SpecialFoo]

If the two classes are put in the same file, it works.

I am using Visual Studio Code, and it approves this configuration (meaning no typo mistakes).

Any ideas?


Solution

  • As stated on their V8 Runtime page:

    Caution: ES6 modules are not yet supported.

    This means exporting and importing of files is not handled by Google Apps Script. This is a bit quirky since all files are in the global scope (and in the order the files are listed) and so you can reference Classes in other files.