Ошибка в наблюдаемом, пытается использовать метод get - PullRequest
0 голосов
/ 19 сентября 2019

Я пытаюсь выполнить рефакторинг настроенного API-интерфейса, например:

 get( route: string, responseType: RespType = 'json', fullResponse: boolean = false, params = null): Observable<any> {
    return this.invoke( 'GET', route, null, responseType, fullResponse, true, params);
  }

до этого:

@Injectable({
  providedIn: 'root'
})
export class DocumentCorrespondenceService {

  allCorrespondence: Observable<DossierEntry>;
  correspondenceEntries: Observable <DossierEntry>;
  attachmentEntries: Observable<DossierEntry>;



constructor(private http: HttpClient) { }


getDossierEntry( type: String = '' ): Observable<Array<DossierEntry>> {
  const entryType = type === '' ? 'all' : 'type/' + type;
  return this.http.get( '/api/patient/{patientUUID}/DossierEntry/' + entryType );
}

getDossierEntryFileData( entryID: number ): Observable<HttpResponse<Blob>> {
  return this.get( '/api/patient/{patientUUID}/DossierEntry/' + entryID + '/fileData', 'pdf', true );
}


}

Но теперь я получаю сообщение об ошибке:

Type 'Observable<Object>' is not assignable to type 'Observable<DossierEntry[]>'.
  The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
    Type 'Object' is missing the following properties from type 'DossierEntry[]': length, pop, push, concat, and 26 more.ts(2322)

Так что я должен изменить?

Спасибо

1 Ответ

2 голосов
/ 19 сентября 2019

В новых версиях Angular (вызывая обновление версии машинописного текста) вы должны указать, какой тип ожидается от вашего http-вызова:

getDossierEntry( type: String = '' ): Observable<DossierEntry[]> {
  const entryType = type === '' ? 'all' : 'type/' + type;
  return this.http.get<DossierEntry[]>( '/api/patient/{patientUUID}/DossierEntry/' + entryType );
}

Примечание: я также изменил ваш тип Array на[], что более похоже на javascript

...