【问题标题】:asp.net core Aurelia project in Typescript - parameter XXX implicitly has 'any' type errorTypescript中的asp.net核心Aurelia项目-参数XXX隐式具有“任何”类型错误
【发布时间】:2018-04-06 04:51:53
【问题描述】:

这是我在 Visual Studio 2017 中遇到的一个错误,应该没问题,但是它在很多地方都失败了,我没有对代码做任何事情 - 从模板中取出它。

这是一个例子:

export function configure(aurelia: Aurelia) {
aurelia.use
    .standardConfiguration()
    .plugin('aurelia-api', config => {
        config.registerEndpoint('weather', 'api/SampleData/WeatherForecasts');

        if (IS_DEV_BUILD) {
            aurelia.use.developmentLogging();
        }

        new HttpClient().configure(config => {
            const baseUrl = document.getElementsByTagName("base")[0].href;
            config.withBaseUrl(baseUrl);
        });

        aurelia
            .start()
            .then(() => aurelia.setRoot(PLATFORM.moduleName("app/app/app")));
    }
  }

在这种情况下,错误出现在配置上(下面的红色波浪线),错误是:

错误 TS7006 (TS) 参数“config”隐式具有“any”类型。

这是另一个:

        import { inject } from "aurelia-framework";
        import {Rest} from 'aurelia-api';

        @inject(Rest)
        export class WeatherForcasts {
          constructor (restClient) {
            restClient.find('product', {
                category: 5,
                name    : {contains: 'mouse'}
              })
              .then(console.log)
              .catch(console.error);
          }
        }

同样的错误——这次红线在“restClient”参数下:

错误 TS7006 (TS) 参数“restClient”隐式具有“any”类型。

为什么会出现此错误,我该如何解决?

【问题讨论】:

    标签: typescript asp.net-core aurelia


    【解决方案1】:

    您遇到这些错误是因为未指定变量的类型。理想情况下,您应该在任何地方添加类型或明确指定 any

    但您也可以在 ts.config 文件中添加此选项以避免这些错误:

    "compilerOptions": {
         "noImplicitAny": false
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-21
      • 2019-11-21
      • 2020-02-02
      • 2022-01-07
      • 2021-05-28
      • 2018-11-30
      • 1970-01-01
      • 2018-05-30
      • 2021-06-09
      相关资源
      最近更新 更多