angular – TypeScript编译器报告无效位置的问题

前端之家收集整理的这篇文章主要介绍了angular – TypeScript编译器报告无效位置的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
整个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本身.

编辑2:这是一个多月,网络伙伴doesn’t seem to be doing anything关于它:(.

解决方法

那是因为在你的tsconfig.json中有一个叫做的属性
“noImplicitAny”:是的.

您有两种选择:

>要么将其设置为false>在每个函数上声明返回类型(返回类型可以是任何)

猜你在找的Angularjs相关文章