0

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);
            }));
    }
}
1
  • 1
    I hate errors like that and I also hate using any. However, have you tried using mergeMap((claim: any) => or mergeMap((claim:Claim) => or return this.claimService.get<Claim>(guid) ? Commented Nov 6, 2019 at 16:00

2 Answers 2

1
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);
            }));
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That didn't occur to me because I wasn't getting a type error on return of(claim). I was also seeing the correct type when hovering but that may be ReSharper. I'll accept as soon as I can.
0

I think if you use this.claimService.get<Claim>(guid) you don't have to type claim in mergeMap(claim =>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.