我一直在网上搜索这个问题的解决方案,可能是一个小问题。
我在一个ts.文件上的函数:
public getHelpContent(question: string[]) {
let theHelp: any[] = [];
theHelp = this.mssqlService.getTheHelpAnswer(question);
console.log("THE HELP:", theHelp);
this.commentContent = theHelp ;
let foundContent: any[] = [];
for (let i = 0; i < this.commentContent.length; i++) {
let hitContent: string[];
hitContent = this.searchHelpItem(question, this.commentContent[i]);
if (hitContent) {
foundContent.push(hitContent);
}
}
return theHelp;
}
mssql-service. ts文件上的函数
getTheHelpAnswer(jsonObj: any): any {
let body = JSON.stringify(jsonObj);
console.log("BODY VAR: ", body);
return this.http
.post<any>(`${this.urlLocation}notification/TheHelp`, body)
.map((response: Response) => response.json())
.catch(this.handleError);
}
和繁荣的处理错误...
private handleError(error: Response | any) {
let errMsg: string;
if (error instanceof Response) {
const body = error || '';
const err = JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
编译时出现错误如下:
error TS2345: Argument of type 'string' is not assignable to parameter of type 'string[]'
当我将此处的:any从:
getTheHelpAnswer(jsonObj: any): any {
到
getTheHelpAnswer(jsonObj: any): Observable<any> { ...
这是我得到的错误:
ERROR in src/app/app-help-state-machine.ts(364,5): error TS2322: Type 'Observable<any>' is not assignable to type 'any[]'.
Property 'includes' is missing in type 'Observable<any>'.
src/app/app-help-state-machine.ts(371,50): error TS2345:
Argument of type 'string' is not assignable to parameter of type 'string[]'.
我不明白问题出在哪里。
更新1:
我忘记添加FUNCTION的签名
public getHelpContent(question: string[]): any[] { ...
但我还是明白...
ERROR in src/app/app-help-state-machine.ts(364,5): error TS2322: Type
'Observable<any>' is not assignable to type 'any[]'.
Property 'includes' is missing in type 'Observable<any>'.
src/app/app-help-state-machine.ts(371,50): error TS2345: Argument of type 'string' is not assignable to parameter of type 'string[]'.
更新2:
我想通了...
查看我回答自己问题的解决方案....
1条答案
按热度按时间xxe27gdn1#
解决方案如下:
我更改了此函数:
致:
在mssql-connect.service.ts文件中,接收函数
更改此内容:
到这个...