我有一个 typescript google data studio 连接器项目,其中所有文件都在一个全局范围内一个接一个地执行。执行顺序定义在
"filePushOrder": [
"src/declaration.ts",
"src/usage.ts"
]
声明.ts:
import CommunityConnector = GoogleAppsScript.Data_Studio.CommunityConnector; // it's only a type
const connector: CommunityConnector = DataStudioApp.createCommunityConnector();
usage.ts:
import GetAuthTypeResponse = GoogleAppsScript.Data_Studio.GetAuthTypeResponse;
function getAuthType(): GetAuthTypeResponse {
return connector
.newAuthTypeResponse()
.setAuthType(connector.AuthType.OAUTH2)
.build();
};
所以如果我在他们的谷歌脚本环境中运行它,它会运行正常,但本地编译器显示错误
Cannot find name 'connector'.
。他们的环境也不支持模块,因此导入和导出不起作用。我如何使所有文件的所有变量都可见?
所以我需要的只是抑制所有与导入/导出相关的错误。顺便说一句,我正在使用 intellij idea,而与 vscode 相关的解决方案对我不起作用。像这个例子:How to enable autocomplete for Google Apps Script in locally-installed IDE
我目前有这个工作解决方案:
声明.ts:
// all the previous content
export { connector };
usage.ts:
// @ts-ignore
// noinspection ES6UnusedImports
import { connector } from './declaration';
// @ts-ignore
const { connector } = { connector };
// all the previous content
和不起作用的例子:
export const connector: CommunityConnector = DataStudioApp.createCommunityConnector();
import { connector } from './declaration';