5

I am trying to turn a Google Script into a Web App, using CLASP.

Is there an existing type definition for the "e" object in doGet(e) / doPost(e) that I can use in the typescript /clasp side of things?

Dustin Michels
  • 2,951
  • 2
  • 19
  • 31

1 Answers1

10

Update:

Latest definitions include events. You may use events like this:

function doGet(e: GoogleAppsScript.Events.DoGet){

Events seem to be in the works. It doesn't have webapps doget event yet. In the mean time, You can install the latest type(@types/google-apps-script@latest) and add the following interface in the Events module inside google-apps-script-events.d.ts

  export interface WebAppsDoGet { //should be inside module Events
    queryString: string,
    parameter: {[key: string]: string; },
    contextPath: string,
    parameters: {
     [key: string]: string[]; },
    contentLength: number
  }

You can then use it like this:

function doGet(e: GoogleAppsScript.Events.WebAppsDoGet){
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • Why is this all crossed out? Is there an update? https://stackoverflow.com/questions/15668119/linking-to-another-html-page-in-google-apps-script suggests that you could use something from the event e to choose between two HTML to show but what is the contents of the webapp event? Where is it documented? https://developers.google.com/apps-script/guides/web Are 'webapps' really apps if they are meant to only have one HTML page? – aNewb Apr 09 '21 at 13:20
  • @aNewb It's striked because the "the works" are finished and you have the latest type definitions link in the update above. The contents of the `e` are documented under "Request parameters" in the [link](https://developers.google.com/apps-script/guides/web) you provided. My answer in the question you linked also provides a full demo of the webapp capabilities. – TheMaster Apr 09 '21 at 16:45