One can add type hints for a plain old javascript object by defining a class for it, and adding a comment above the constructor defining the parameter types
onEdit(e) (when a cell is edited) has an event, e as an input.
Unfortunately, it there is no Event type in the script editor.
We can fix that by defining an event class and adding a type hint for the parameter e like so:
class User {
/**
* @param {string} email
* @param {string} nickname
*/
constructor(email, nickname) {
this.email = email;
this.nickname = nickname;
}
}
class Range {
/**
* @param {Number} columnEnd
* @param {Number} columnStart
* @param {Number} rowEnd
* @param {Number} rowStart
*/
constructor(columnEnd, columnStart, rowEnd, rowStart) {
this.columnEnd = columnEnd;
this.columnStart = columnStart;
this.rowEnd = rowEnd;
this.rowStart = rowStart;
}
}
class Event {
/**
* @param {string} value
* @param {User} user
* @param {ScriptApp.AuthMode} authMode
* @param {Range} range
* @param {string} oldValue
*/
constructor(value, user, authMode, range) {
this.value = value;
this.user = user;
this.authMode = authMode;
this.range = range;
}
}
/**
* @param {Event} e
*/
function onEdit(e) {
// now we have autocompletion on e properties
SpreadsheetApp.getUi().alert(JSON.stringify(e));
SpreadsheetApp.getUi().alert(e.user.email);
}