整个 main.ts:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
// depending on the env mode, enable prod mode or add debugging modules
if (process.env.ENV === 'build') {
enableProdMode();
}
export function main() {
return platformBrowserDynamic().bootstrapModule(AppModule);
}
if (document.readyState === 'complete') {
main();
} else {
document.addEventListener('DOMContentLoaded', main);
}
一些错误(不是全部):
[default] /xxx/src/main.ts:11:96
Index signature of object type implicitly has an 'any' type.
...
[default] /xxx/src/main.ts:11:853
Parameter 'store' implicitly has an 'any' type.
报告的位置(例如 11:96、11:853)毫无用处 - 那里什么也没有。我应该如何处理这些严重报告的错误?我怎样才能找到这些错误的真实位置?如何修复它,以便它正确报告?
我正在使用这个种子 - https://github.com/preboot/angular2-webpack/ (我认为主文件未修改)。
我在 tsconfig.json
中添加了以下内容:
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
请注意,我需要所有这些支票。
同样奇怪的是,它报告的标识符不在我的代码中。例如:
Parameter 'dependencies' implicitly has an 'any' type.
由于这个和大量的错误,我开始怀疑它在库中报告错误(这很奇怪,因为我有 skipLibCheck
)或在连接的结果文件中(这也很奇怪,因为所有东西都被编译成 es5)。但我没有使用 TypeScript 编译器或 Webpack 的经验,所以我真的不能说。
Edit1:在 TypeScript repo 询问后,很明显编译器工作正常。罪魁祸首似乎是 TS 加载器或 webpack 本身。
Edit2:一个多月过去了,webpack 伙计们 doesn't seem to be doing anything关于它:(。
最佳答案
那是因为在你的 tsconfig.json
中有一个名为
“noImplicitAny”:true
。
你有两个选择:
- 要么将其设置为 false
- 声明每个函数的返回类型(返回类型可以是
任何
)
关于angular - TypeScript 编译器在无效位置报告问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40279238/