如何在应用程序脚本编辑器中强制自动完成不明确的变量?

Cod*_*per 1 google-apps-script

function onEdit(e)
  e... //I want auto completion
  var range = e.range();
  e.... //I want auto completion
}
Run Code Online (Sandbox Code Playgroud)

如何强制自动完成变量(例如在 onEdit 中),有没有办法显式指定 e 的类型用于自动完成?

  1. 如何查看 e 的数据类型是什么。
  2. 如何显式指定 e 是 Google 应用程序脚本编辑器中自动完成的数据类型。

And*_*ini 5

在新的 Apps Script IDE 中,您可以使用 JSDoc 来自动完成内置类型。

/**
 * Clears the content of the range, leaving the formatting intact.
 * @param {SpreadsheetApp.Range} range The range to clear the content
 * @return {SpreadsheetApp.Range} This range, for chaining.
 */
function clearContent(range) {
  range.clearContent()
}
Run Code Online (Sandbox Code Playgroud)

Event 对象似乎没有内置声明,但您始终可以创建自己的声明。

/**
 * @typedef {Object} onEditEvent 
 * @property {ScriptApp.AuthMode} authMode A value from the ScriptApp.AuthMode enum.
 * @property {string} oldValue Cell value prior to the edit, if any. Only available if the edited range is a single cell. 
 *                    Will be undefined if the cell had no previous content.
 * @property {SpreadsheetApp.Range} range A Range object, representing the cell or range of cells that were edited.
 * @property {SpreadsheetApp.Spreadsheet} source A Spreadsheet object, representing the Google Sheets file to which the script is bound.
 * @property {string} triggerUid ID of trigger that produced this event (installable triggers only).
 * @property {User} user A User object, representing the active user, if available (depending on a complex set of security restrictions).
 * @property {string} value New cell value after the edit. Only available if the edited range is a single cell.
 */


/**
 * @param {onEditEvent} e The onEdit event.
 */
function onEdit(e) {
  e... // type to show autocomplete 

}
Run Code Online (Sandbox Code Playgroud)

自动完成菜单