Google Apps Script inheritance on V8

434 Views Asked by At

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?

2

There are 2 best solutions below

1
Sunny Patel On BEST ANSWER

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.

0
coccoinomane On

As mentioned by Sunny Patel, the V8 runtime does not support modules. However, you might look into Clasp and its TypeScript feature, which partially supports modules.

Related links: