Skip to content

Variables, parameters, and triggers

Why Google Apps Script stops autocompleting your variables

Type SpreadsheetApp. at script.google.com and suggestions appear. Store a sheet in a variable, pass range into a helper function, or type e. inside onEdit(e), and autocomplete often goes blank. Here is why that happens and how JSDoc comments plus myFunction (Error Checker for Google Apps Script) restore typed completions inside Chrome.

Why suggestions disappear

Three places where native Apps Script autocomplete stops working.

The built-in editor recognizes global services such as SpreadsheetApp and GmailApp. Once a value moves into a variable, a function parameter, or a trigger event, the native editor loses its type.

01 · Local variables

Values stored in variables

Type SpreadsheetApp. and the native editor suggests methods. Store a string, array, or returned Apps Script object in a local variable and type a dot, and the editor often shows no typed suggestions or return-type tooltip.

02 · Helper parameters

sheet or range passed to a helper

Inside function formatRow(sheet, range), plain JavaScript does not say what type sheet or range holds. Without type information, typing sheet. or range. inside the helper shows no typed method list.

03 · Trigger events

The e parameter in onEdit(e) and onFormSubmit(e)

Apps Script passes an event object e only when the trigger runs. The native editor does not know which trigger event e represents, so typing e. does not show e.range, e.value, or e.namedValues.

JSDoc annotations

Add JSDoc @param types to autocomplete e, sheet, and range.

JSDoc comments tell the language service which Apps Script type a parameter holds. Apps Script ignores comments at runtime, so your code stays plain JavaScript with no build step.

Example 01 · Trigger event e

Get autocomplete for e in onEdit(e)

Without a type on e, it is easy to write e.range() by mistake and hit TypeError: e.range is not a function after you edit a cell. Adding /** @param {Events.SheetsOnEdit} e */ tells myFunction that e.range is a SpreadsheetApp.Range property, unlocking completions for e.range, e.value, e.oldValue, and e.source.

Untyped e · throws TypeError 1 changed line
function onEdit(e) {
  const cell = e.range();
  Logger.log(cell.getA1Notation());
}
Typed with Events.SheetsOnEdit 2 changed lines
/** @param {Events.SheetsOnEdit} e */
function onEdit(e) {
  const cell = e.range;
  Logger.log(cell.getA1Notation());
}

Example 02 · Helper function parameters

Get autocomplete on sheet and range inside helpers

A helper function without JSDoc leaves sheet and range as any. Adding SpreadsheetApp.Sheet and SpreadsheetApp.Range restores method completions and argument checks inside the function. With myFunction installed, the rule-based TS7006 quick fix reads how markStatusRow is called in your project and offers to write that JSDoc block for you.

Parameters left as any 0 changed lines
function markStatusRow(sheet, range) {
  const row = range.getRow();
  sheet.getRange(row, 4).setValue('Reviewed');
}

function reviewActiveSelection() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const range = sheet.getActiveRange();
  if (range) markStatusRow(sheet, range);
}
Typed with JSDoc @param 4 changed lines
/**
 * @param {SpreadsheetApp.Sheet} sheet
 * @param {SpreadsheetApp.Range} range
 */
function markStatusRow(sheet, range) {
  const row = range.getRow();
  sheet.getRange(row, 4).setValue('Reviewed');
}

function reviewActiveSelection() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const range = sheet.getActiveRange();
  if (range) markStatusRow(sheet, range);
}

Trigger event reference

Match the JSDoc event type to the trigger source.

Different triggers populate different properties on e. A form-submit trigger bound to a Google Form passes e.response, while an On form submit trigger bound to the response spreadsheet passes e.values, e.namedValues, and e.range.

Trigger or handlerJSDoc @param typeCommon properties on e
onEdit(e) in Google SheetsEvents.SheetsOnEdite.range (Range), e.value, e.oldValue, e.source (Spreadsheet), e.user
onFormSubmit(e) in response SheetEvents.SheetsOnFormSubmite.range (Range), e.values (string[]), e.namedValues, e.triggerUid
onFormSubmit(e) in Google FormsEvents.FormsOnFormSubmite.response (FormResponse), e.source (Form), e.triggerUid
doPost(e) in a web appEvents.DoPoste.postData (contents, type, length, name), e.parameter, e.parameters, e.queryString

New to triggers? Read Google Apps Script triggers explained for how simple and installable triggers run and why clicking Run does not supply e.

Inside script.google.com

Typed completions in Chrome, without VS Code or clasp.

myFunction, listed on the Chrome Web Store as Error Checker for Google Apps Script, adds variable, parameter, and cross-file autocomplete right inside the Apps Script editor you already use.

Local variables and built-in services
Tracks the type of each local variable across JavaScript built-ins, Apps Script services generated from the live runtime, and the 31 advanced services, ranking completions that fit at the cursor.
Cross-file calls in one project scope
Indexes every .gs file open in your project so functions and globals declared in another file appear in autocomplete and Go to Definition.
Rule-based JSDoc inference (TS7006)
Follows how a helper function is called across your project and offers a quick fix that writes the JSDoc @param types for you. You review the preview before applying the edit.
Free, local, and no Drive or Gmail scopes
Autocomplete, hover documentation, signature help, diagnostics, and rule-based quick fixes are free without an account and run locally in Chrome. myFunction never runs or saves your script and never requests Google OAuth access to Apps Script projects, Google Drive, Gmail, or Calendar. Read the security details or see how to check Apps Script before running.

Questions

Frequently asked questions.

Why doesn't Google Apps Script autocomplete my variables?
The native editor at script.google.com knows top-level service names such as SpreadsheetApp and GmailApp, but it often loses track of a value once you store it in a local variable, pass it to a helper function, or receive it as a trigger parameter. Installing myFunction (Error Checker for Google Apps Script) adds a TypeScript language service to script.google.com that tracks variable types as you edit.
Why doesn't autocomplete work on sheet or range inside my function?
A plain JavaScript function such as function highlightRow(sheet, range) gives the editor no type information for its parameters, so sheet and range default to untyped values. Add JSDoc @param comments such as @param {SpreadsheetApp.Sheet} sheet and @param {SpreadsheetApp.Range} range, or let myFunction infer those JSDoc types from how the function is called across your project (TS7006).
How do I get autocomplete for e in onEdit(e) or onFormSubmit(e)?
Add a JSDoc comment above the trigger function with the matching event type: /** @param {Events.SheetsOnEdit} e */ for onEdit(e), /** @param {Events.SheetsOnFormSubmit} e */ for a spreadsheet-bound form submit trigger, or /** @param {Events.FormsOnFormSubmit} e */ for a Form-bound script. With myFunction installed in Chrome, typing e. then lists the properties on that event object.
How do I know what properties e has in a Google Apps Script trigger?
The properties on e depend on which trigger fired. A Sheets edit trigger (Events.SheetsOnEdit) provides e.range, e.value, e.oldValue, and e.source. A Sheets form-submit trigger (Events.SheetsOnFormSubmit) provides e.range, e.values, and e.namedValues. A Form-bound submit trigger (Events.FormsOnFormSubmit) provides e.response and e.source. A web-app doPost(e) handler (Events.DoPost) provides e.postData, e.parameter, and e.parameters.
Do I need VS Code or clasp to get variable autocomplete in Apps Script?
No. myFunction (Error Checker for Google Apps Script) runs inside Chrome on script.google.com, giving you typed variable completions, cross-file navigation, and rule-based JSDoc inference for free without an account and without installing VS Code, Node.js, or clasp.

Chrome Web Store

Add variable and trigger autocomplete to script.google.com.

Install myFunction (Error Checker for Google Apps Script) from the Chrome Web Store. Typed completions, hover docs, diagnostics, and rule-based JSDoc quick fixes are free without an account.