Я искал в Интернете решение этой, что, вероятно, незначительной проблемы.
Моя функция на один тс.file:
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[]'
Когда я изменяю: любой здесь с:
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:
Я забыл добавить подпись ФУНКЦИИ
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:
Я понял это ...
Посмотреть решениегде я ответил на свой вопрос ....