Is there a type definition for the doGet/doPost trigger function event object?
Asked Answered
M

1

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?

Maya answered 24/5, 2019 at 21:46 Comment(0)
H
12

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){
Heliotherapy answered 24/5, 2019 at 23:4 Comment(2)
Why is this all crossed out? Is there an update? #15668619 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? developers.google.com/apps-script/guides/web Are 'webapps' really apps if they are meant to only have one HTML page?Doble
@Doble 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 you provided. My answer in the question you linked also provides a full demo of the webapp capabilities.Heliotherapy

© 2022 - 2024 — McMap. All rights reserved.