typescript - 出现错误“TS2451:无法重新声明块范围变量‘全局’。” 使用打字稿和 webpack?
问题描述
我正在尝试使用 Typescript 和 Webpack 为 Google Apps Script 建立一个项目。
我遇到了一个我不明白的奇怪错误:
TS2451:无法重新声明块范围变量“全局”
global
用于gas-webpack-plugin
在 Google Apps 脚本中创建可访问的函数。
我在 webpack ( index.ts
) 的入口点中使用它:
declare let global: any;
global.banana = () => {
// Method used in Google Apps Script
};
我收到此错误,但我不确定我在哪里重新声明global
. 我尝试排除node_modules
:tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"module": "es2015"
},
"exclude": [
"node_modules"
],
}
如果我在声明行之前添加导入,错误就会消失。导入的内容似乎并不重要。这是我添加的。import { Whatever } from './whatever';
whatever.ts
内容:
export class Whatever {
static whatever(): string {
return "Nothing makes sense";
}
}
显然我有一个解决方法,只是想知道为什么脚本会因错误而停止?
解决方案
推荐阅读
- redis - Redis UNSUBSCRIBE 不会删除频道
- mysql - 为什么我以 root 身份登录时没有所有权限?
- analytics - AJAX (SPA) 上的 Facebook Pixel 页面浏览量初始化
- reactjs - 如何在 React Native 中实现点击编辑、选择项目和删除功能
- scala - Applicative from Category 理论中的 map 函数有什么作用?
- c# - 结合 Interlocked.Increment 和 Interlocked.Exchange
- java - 如何在android应用程序中从url显示Pdf文件
- php - 平台相关函数
- c# - 格式化 TimeSpan 以仅显示相关的时间单位
- javascript - 正则表达式 - 可能重复的模式