Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What will be the return type of function?

export interface IResponseCount {
  count: number;
  status?: number;
  success: boolean;
}



extractResponse() {
    return (source: Observable<IResponseCount>) => {
      return source.pipe(
        map(value => {
          if (!value.success) {
            throw new Error(..);
          }
          return value.count;
        })
      );
    };
  }

What will be the return type of function extractResponse. Ex. extractResponse(): SOMETHING {…}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Based on your provided code the return type is following:

(source: Observable<IResponseCount>) => Observable<number>

Because your function returns a function which takes an Observable and returns an Observable which provides a number.

So, your code would look like this with the return type:

extractResponse(): (source: Observable<IResponseCount>) => Observable<number> {
  return (source: Observable<IResponseCount>) => {
    return source.pipe(
      map(value => {
        if (!value.success) {
          throw new Error('..');
        }
        return value.count;
      })
    );
  };
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading