function onEdit(e)
e... //I want auto completion
var range = e.range();
e.... //I want auto completion
}
如何在 onEdit 等变量上强制自动完成,有没有办法明确指定 e 的类型以实现自动完成?
在新的 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()
}
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
}
出于文档目的,我将其发布为
community wiki
。
正如其他人在评论中已经说过的那样,您无法使用 Apps 脚本编辑器对事件对象使用自动完成功能。
解决方法,也正如其他用户所引用的那样,是使用 clasp 并使用可以启用自动完成功能的 IDE。