我正在尝试重构自定义 api get,如下所示: 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 回答
有只小跳蛙
TA贡献1824条经验 获得超8个赞
在新的 Angular 版本中(导致升级 typescript 版本),您必须指定 http 调用预期的类型:
getDossierEntry( type: String = '' ): Observable<DossierEntry[]> {
const entryType = type === '' ? 'all' : 'type/' + type;
return this.http.get<DossierEntry[]>( '/api/patient/{patientUUID}/DossierEntry/' + entryType );
}
注意:我还用 改变了你的Array类型[],这更像是“javascript”
添加回答
举报
0/150
提交
取消