【发布时间】:2023-02-24 02:21:45
【问题描述】:
抱歉,如果问题不清楚,但我不知道该怎么说。我有一个使用 Typescript 开发的 Google Ads Script 项目。我使用 BigQuery 库。如您所知,在 Google Ads 中您不需要导入任何库(如在 Node.js 中),因为它们已经在全球范围内可用。
所以我只需要从https://www.npmjs.com/package/@types/google-apps-script导入类型。它的工作方式是取消任何错误,如未定义 BigQuery 等。但是我可以导入和使用任何特定接口吗?
例如,我有一个返回TableFieldSchema 的函数。
const bqQuerySchemaGenerator = (description: string, name: string, type: string) => {
const nameFieldSchema : any = BigQuery.newTableFieldSchema();
nameFieldSchema.description = description;
nameFieldSchema.name = name;
nameFieldSchema.type = type;
return nameFieldSchema
}
我想定义一个类型来显示此函数返回的内容。我知道通常如果我使用相应的库我会导入类似
import {TableFieldSchema} from "google-apps-script"
但正如我提到的,我不使用任何外部库,所以我会想象这样的事情
import type {TableFieldSchema} from "@types/google-apps-script"
const bqQuerySchemaGenerator = (description: string, name: string, type: string) : TableFieldSchema => {
const nameFieldSchema : any = BigQuery.newTableFieldSchema();
nameFieldSchema.description = description;
nameFieldSchema.name = name;
nameFieldSchema.type = type;
return nameFieldSchema
}
但它不起作用。如何导入这些类型?甚至有可能吗?
【问题讨论】:
标签: typescript google-ads-script