On December 7, 2020, new IDE has been released. Ref This has been helping users develop various applications using Google Apps Script with the new IDE very much. When it develops scripts and applications using Google Apps Script with the new IDE, it is considered that the existence of JSDoc in the script will be helpful for both the developers and the client users, because it is reflected in the auto-completion. However, when I tried to add the built-in Class objects of Google Apps Script for returning an object using JSDoc, unfortunately, I'm worried that the detailed official documents related to JSDoc for Google Apps Script are few. Ref and Ref In this report, I would like to introduce a method for adding JSDoc for using auto-completion of the built-in Class objects to functions of Google Apps Script.
Here, as a simple sample, it is considered JSDoc for returning Class Spreadsheet object from a function.
Please open the script editor of Google Apps Script.
Please write SpreadsheetApp.getActiveSpreadsheet
on the script editor. By this, the dialog of the auto-completion is opened as follows.
You can see the method name and return value at (method) SpreadsheetApp.getActiveSpreadsheet(): SpreadsheetApp.Spreadsheet
in the dialog. Here, you can confirm that the name of Class Spreadsheet object is SpreadsheetApp.Spreadsheet
. This can be used as the type of return value from a function as JSDoc.
Please copy and paste the following script.
/**
* @returns {SpreadsheetApp.Spreadsheet} sample
*/
function sample() {
// do something.
}
function main() {
sample();
}
In this sample script, the function sample()
is called from main()
. Here, when you write sample()
in the function main()
, the following dialog can be seen.
You can see the return value is SpreadsheetApp.Spreadsheet
. And, when you add .
as follows,
You can see the methods of Class Spreadsheet in the auto-completion.
By this flow, the auto-completion of Class Spreadsheet object can be returned from a function.
Here, I would like to introduce various samples. I guess that those samples might help in understanding the use of Class objects of Google Apps Script with JSDoc.
/**
* @returns {SpreadsheetApp.Sheet} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {SpreadsheetApp.Range} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {DriveApp.File} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {UrlFetchApp.HTTPResponse} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {Drive_v3.Drive.V3.Collection.FilesCollection} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {Drive_v3.Drive.V3.Collection.PermissionsCollection} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {Sheets_v4.Sheets.V4.Collection.SpreadsheetsCollection} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
/**
* @returns {Sheets_v4.Sheets.V4.Collection.Spreadsheets.ValuesCollection} sample
*/
function sample() {
// do something
}
function main() {
sample();
}
- This method can be used in the library for Google Apps Script.