Reputation: 49301
I don't understand why the line this.claim = claim;
has the error "Cannot convert type 'A' to type 'Claim'". I need to return an observable because this function is called in a resolver. I don't actually need to return the claim itself, I just need to set the property on ClaimStoreService, but I couldn't figure out how to return an empty or void observable.
export class ClaimStoreService {
constructor(private readonly claimService: ClaimService) { }
claim: Claim;
getClaim(guid: string): Observable<Claim> {
return this.claimService.get(guid).pipe(
take(1),
mergeMap(claim => {
// Cannot convert type 'A' to type 'Claim'
this.claim = claim;
return of(claim);
}));
}
}
Upvotes: 0
Views: 77
Reputation: 1495
I think if you use this.claimService.get<Claim>(guid)
you don't have to type claim
in mergeMap(claim =>
.
Upvotes: 0
Reputation: 1272
claim: Claim;
getClaim(guid: string): Observable<Claim> {
return this.claimService.get(guid).pipe(
take(1),
// give type here will solve your issue
mergeMap((claim:Claim) => {
this.claim = claim;
return of(claim);
}));
}
Upvotes: 1