使用云函式構建 Google App 腳本時,是否有原始 JSON 模式的 Typescript 定義,如下所述:https : //developers.google.com/workspace/add-ons/alternate-runtimes-quickstart
我明白了,@types/google-apps-script但這似乎沒有定義預期的 JSON 模式(我假設printJSON()最終呼叫的時間)
或者,有沒有辦法匯入 App Script 庫,所以我可以呼叫printJSON()自己并使用他們的框架?
{
"action": {
"navigations": [
{
"pushCard": {
"header": {
"title": "Cats!"
},
"sections": [
{
"widgets": [
{
"textParagraph": {
"text": "Your random cat:"
}
},
{
"image": {
"imageUrl": "https://cataas.com/cat"
}
}
]
}
]
}
}
]
}
};
uj5u.com熱心網友回復:
正如您在問題中所描述的,DefiniteTyped 中有一個 CardService 的已發布介面,根據此備用運行時博客文章,該介面構建了一個與預期的 JSON 格式匹配的 protobuf。盡管 CardService 和 JSON 格式很可能源自同一個 protobuf,但我無法在可公開訪問的地方找到該源。
盡管它們不是 TypeScript 格式,但在完整的非快速啟動備用運行時檔案中有一個“示例 JSON 模式”部分,然后您可以使用json-schema-to-typescript 之類的庫將其轉換為 TypeScript 宣告。
uj5u.com熱心網友回復:
您可以使用typeof來獲取物件的型別。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/408570.html
標籤:
