1

I’m building a Google Apps Script library and I’d like to expose some constants as a nested object.

var CONFIG = {
  LEVEL0: {
    LEVEL1_A: 'A',
    LEVEL1_B: 'B'
  }
};

When I use this library in another project, autocomplete detects CONFIG and CONFIG.LEVEL0, but not CONFIG.LEVEL0.LEVEL1_A and CONFIG.LEVEL0.LEVEL1_B.

Is there a way to make the Apps Script editor at script.google.com provide autocomplete for deeply nested constants in a library? Or is this simply a limitation of the Apps Script autocomplete engine?

4
  • Put the property names in the var declaration with an underscore between ", I.E., "LEVEL1_A". If that doesn't work, try adding a JSDoc comment for the type of your variable. See jsdoc.app/tags-type. Commented Sep 10 at 16:04
  • Flattening the object structure is the most reliable way to get autocomplete to work, as the Google Apps Script editor struggles to provide suggestions for deeply nested objects instead of CONFIG.LEVEL0.LEVEL1_A to this CONFIG.LEVEL0_LEVEL1_A. Commented Sep 10 at 19:04
  • 1
    Indeed I tried both things that Wicket propsed and they didn't work. Seems like what Lime Husky proposed is the only way in the script.google.com editor. Commented Sep 10 at 21:30
  • 2
    Related: stackoverflow.com/a/70856689/1595451 Commented Sep 10 at 23:23

1 Answer 1

1

Flattening the object structure is the most reliable way to get autocomplete to work, as the Google Apps Script editor struggles to provide suggestions for deeply nested objects instead of CONFIG.LEVEL0.LEVEL1_A to this CONFIG.LEVEL0_LEVEL1_A.

So when you type CONFIG. the editor will show LEVEL0_LEVEL1_A and LEVEL0_LEVEL1_B, which it can autocomplete.

From

var CONFIG = {
  LEVEL0: {
    LEVEL1_A: 'A',
    LEVEL1_B: 'B'
  }
};

To

var CONFIG = {
  LEVEL0_LEVEL1_A: 'A',
  LEVEL0_LEVEL1_B: 'B'
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.