Are there Typescript definitions for the raw JSON schema when building a Google App Script using a cloud function, as described here: https://developers.google.com/workspace/add-ons/alternate-runtimes-quickstart
I see @types/google-apps-script but that doesn't seem to define the expected JSON schema (i assume when printJSON() is ultimately called)
Alternatively, is there a way to import the App Script library, so I can call printJSON() myself and use their framework?
{
"action": {
"navigations": [
{
"pushCard": {
"header": {
"title": "Cats!"
},
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "Your random cat:"
}
},
{
"image": {
"imageUrl": "https://cataas.com/cat"
}
}
]
}
]
}
}
]
}
};
CodePudding user response:
As you described in the question, there is a published interface for CardService in DefinitelyTyped, which according to this alternate runtimes blog post builds a protobuf that matches the JSON format expected. Though CardService and the JSON format are likely derived from the same protobuf, I could not find that source in a publicly-accessible place.
Though they're not in TypeScript format, there is a "sample JSON schemas" section in the full non-quickstart Alternate Runtime docs, which you could then convert to TypeScript declarations using a library like json-schema-to-typescript.
CodePudding user response:
You can use typeof to get type of an object.
const obj={
"action": {
"navigations": [
{
"pushCard": {
"header": {
"title": "Cats!"
},
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "Your random cat:"
}
},
{
"image": {
"imageUrl": "https://cataas.com/cat"
}
}
]
}
]
}
}
]
}
};
type mytype = typeof obj
