I have a function with the ability to call out to a service and use the resulting data object response from the service to be used to generate the CRUD code necessary to interact with that endpoint. So I created an asynchronous Schematic that would call to a service, wait for that service to respond, and then continue when we were ready.
My code is something like this:
function waitingRule(options: any): Rule {
return (tree: Tree) => {
return new Observable<Tree>((observer) => {
fetch('someUrl.com/') // any async operation
.then(res => res.json())
.then(data => {
observer.next(tree);
observer.complete();
})
.catch(((err: any) => {
observer.error(err);
});
});
};
}
This worked well until I upgraded to Angular 9. Now I get the following error:
Type '(tree: Tree) => Observable' is not assignable to type 'Rule'. Type 'Observable' is not assignable to type 'void | Tree | Rule | Observable | Promise<void | Rule>'.
In previous versions a rule can return either a Tree or an Observable, but it seems this is not possible with the last versions. Any idea of how making this working again?