0

If @typedef is described in a library it seems that autocomplete doesn't work as expected on a file which imports library; object type is turned into any. Is there any solution to tell object's structure to another script?

Please note that I don't want to use non-gas technique like TypeScript. Thanks.

/**
 * @typedef {Object} myVegetable
 * @property {string} name
 * @property {number} price
 */
/** @type {myVegetable} */
var myVegetable = { name: "carrot", price: 1 };

enter image description here

img1 - @typedef works as expected in same file.

enter image description here

img2 - type myVegetable is turned into any on file which imports library.

Takuya HARA
  • 499
  • 1
  • 3
  • 17

1 Answers1

-1

GAS Alone Does Not Support Typescript

Google Apps Script (GAS) does not support typescript without adding additional tools. Based on the article Develop Apps Script using TypeScript, you may incorporate typescript in GAS with clasp. However, this requires you to install the following to enable your local development environment:

  1. Node and npm
  2. Clasp
  3. Type definitions for Apps Script
  4. Visual Studio Code (for TypeScript IDE autocompletion)

References:

For further details, you may view the following links:

  1. Develop Apps Script using TypeScript
  2. Command Line Interface using clasp
PatrickdC
  • 1,385
  • 1
  • 6
  • 17
  • May I ask whether you needed the library with @typedef to be compatible with GAS or you just needed a fix to the autocomplete bug? It was in my understanding that you needed to use the library with typescript format that's why I based my answer on the Develop Apps Script using TypeScript article by Google as a workaround. – PatrickdC Jun 30 '22 at 01:29