After fulfilling a promise that creates and subscribes to an observable, I'm looking to convert this promise into an observable and return it for subscription elsewhere. This includes the inner observable as well. To achieve this, I initially tried using from
to convert the promise and then used concatMap
to chain the inner observable. Unfortunately, while working on the code, I encountered an error related to the xfdfString
string variable fetched from the initial promise at the start of the concatMap
. It seems like my new function's inner observable might not be returning an observable itself. Despite multiple attempts to fix this issue, I haven't had any success yet. Any suggestions or ideas would be greatly appreciated.
Error:
Argument of type '(xfdfString: string) => void' is not assignable to parameter of type '(value: string, index: number) => ObservableInput<any>'.
Type 'void' is not assignable to type 'ObservableInput<any>'.ts(2345)
Original function:
save() {
const { annotManager } = this.wvInstance;
annotManager.exportAnnotations({ links: false, widgets: false }).then(xfdfString => {
const requestId = (<SignatureDocumentData>this.task.actionData).requestId;
const data: SignDocument = { encodedDocument: encodeBase64(xfdfString) };
this.documentService.signDocument(requestId, data)
.pipe(
switchMap(signResponse => this.workflowService.completeAction(this.task.id)),
switchMap(nextTask => {
if (!nextTask) {
return this.workflowService.completeFolder();
} else {
return observableOf(nextTask);
}
}),
).subscribe(response => console.log(response));
});
}
My attempt at using a higher-order observable to instead return one observable:
save(): Observable<any> {
const { annotManager } = this.wvInstance;
const docViewerobservable = from(annotManager.exportAnnotations({ links: false, widgets: false }));
return docViewerobservable.pipe(
concatMap(xfdfString => {
const requestId = (<SignatureDocumentData>this.task.actionData).requestId;
let data = { encodedDocument: encodeBase64(xfdfString) };
this.documentService.signDocument(requestId, data)
.pipe(
switchMap(signResponse => this.workflowService.completeAction(this.task.id)),
switchMap(nextTask => {
if (!nextTask) {
return this.workflowService.completeFolder();
} else {
return observableOf(nextTask);
}
})
);
})
);
}