asp.net Typescript 中的核心 Aurelia 项目 - 参数 XXX 隐式具有 'any' 类型错误
asp.net core Aurelia project in Typescript - parameter XXX implicitly has 'any' type error
这是我在 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")));
}
}
在这种情况下,错误出现在配置上(下面的红色波浪线),错误为:
Error TS7006 (TS) Parameter 'config' implicitly has an 'any' type.
这是另一个:
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"参数下:
Error TS7006 (TS) Parameter 'restClient' implicitly has an 'any' type.
为什么会出现此错误,我该如何解决?
你有这些错误是因为你的变量类型没有指定。理想情况下,您应该在任何地方添加类型或明确指定 any
.
但您也可以在 ts.config 文件中添加此选项以避免这些错误:
"compilerOptions": {
"noImplicitAny": false
}
这是我在 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")));
}
}
在这种情况下,错误出现在配置上(下面的红色波浪线),错误为:
Error TS7006 (TS) Parameter 'config' implicitly has an 'any' type.
这是另一个:
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"参数下:
Error TS7006 (TS) Parameter 'restClient' implicitly has an 'any' type.
为什么会出现此错误,我该如何解决?
你有这些错误是因为你的变量类型没有指定。理想情况下,您应该在任何地方添加类型或明确指定 any
.
但您也可以在 ts.config 文件中添加此选项以避免这些错误:
"compilerOptions": {
"noImplicitAny": false
}