-
Notifications
You must be signed in to change notification settings - Fork 4
Enhancing Autocompletion in Google Apps Script with Telesun
Google Apps Script libraries often come with a notable limitation: a lack of comprehensive autocompletion for anything beyond global functions and variables. This can slow down development and increase the likelihood of errors due to typos or incorrect method calls. To address this, Telesun offers full types definitions, enabling developers to enjoy robust autocompletion support directly within their projects. Follow these steps to set up autocompletion for Telesun in your Google Apps Script project:
-
Create a File for Types: Begin by creating a new file in your project named
types
. -
Copy Type Definitions: Visit the Telesun Typedef documentation page at Telesun Typedef Documentation. Copy the entire content of the typedef section and paste it into the
types
file you created.
When you instantiate the Telesun class in your script, use the /** @type telesun */
annotation above the instantiation line. This tells the editor that your variable is of the Telesun type, thus enabling autocompletion for methods and properties associated with the Telesun class.
/** @type telesun */
const telesun = new Telesun.connectBot('<your-bot-token>');
telesun.use(ctx => {
// Here, you get full autocompletion support for the ctx object
});
For scenarios where you're passing a callback function to Telesun handlers and wish to benefit from autocompletion within that function, simply use the /** @type telesun */
annotation. However, to ensure autocompletion support for the ctx
methods when defining separate functions, you should annotate the function parameter with /** @param {ctx} ctx */
, where Type
is the specific type you're working with, typically related to the context or any other relevant object from the Telesun library.
/** @param {ctx} ctx */
function send(ctx) {
// With this, you gain full autocompletion support for the ctx object
}
or:
function send(/** @type {ctx} */ctx) {
// With this, you gain full autocompletion support for the ctx object
}
By following these steps, you integrate comprehensive autocompletion support into your Google Apps Script project, significantly enhancing the development experience with Telesun. This setup not only speeds up your coding process but also reduces the potential for errors, making your script development smoother and more efficient.
- Manager Classes:
- Mail:
- Google Spreadsheet:
- Best Practice:
- Getting Updates:
- Example Types:
- Example Bots: