Why map doesn't work after upgrading RxJS to v6.3











up vote
0
down vote

favorite












I have a similar case to one described in this post.



I have a user login service, which (among other things) verifies if user's token is still valid. The server's response is defined in an interface:



export interface UserVerifyResponse {
success: boolean
}


My aim was to create an observable that will return a boolean value depending on whether user is verified. This code was working with RxJS v6.2:



authenticate(): Observable<boolean> {
return this.http.get<boolean>(
this.apiUrl+'/verify_user'
).pipe(
map<UserVerifyResponse, boolean>((receivedData: UserVerifyResponse) => {
return receivedData.success;
}),
tap((data: boolean) => {console.log("User authenticated", data)}),
catchError(this.handleError)
)
}


However, now that I have updated RxJS to v6.3 I get this error:



ERROR in src/app/login/user.service.ts(50,13): error TS2345: Argument of type 'OperatorFunction<UserVerifyResponse, boolean>' is not assignable to parameter of type 'OperatorFunction<boolean, boolean>'.
Type 'UserVerifyResponse' is not assignable to type 'boolean'.


It bothers me, because I use this approach of mapping API response to an internal class or a primitive (in other place I have a service which uses http.get<T>) and now I wonder if I should force RxJS 6.2 or there is an easy way to migrate to 6.3. I can rewrite all of them as it is described in the answer to the above mentioned post, but I I want to return a boolean value and my approach looks clearer in my opinion.



Any suggestions?










share|improve this question






















  • By this this.http.get<boolean> you're saying that this request will return an Observable emitting booleans. But then you use map<UserVerifyResponse, boolean> where UserVerifyResponse is an object instead of boolean.
    – martin
    Nov 10 at 15:06










  • Because this is what I want the request to return. With RxJS v6.2 I was able to translate the response that I received from the API (of type UserVerifyResponse) to boolean, so finally the http.get would return Observable of type boolean. Why was it acceptable previously and now it is wrong logic?
    – george007
    Nov 10 at 15:23















up vote
0
down vote

favorite












I have a similar case to one described in this post.



I have a user login service, which (among other things) verifies if user's token is still valid. The server's response is defined in an interface:



export interface UserVerifyResponse {
success: boolean
}


My aim was to create an observable that will return a boolean value depending on whether user is verified. This code was working with RxJS v6.2:



authenticate(): Observable<boolean> {
return this.http.get<boolean>(
this.apiUrl+'/verify_user'
).pipe(
map<UserVerifyResponse, boolean>((receivedData: UserVerifyResponse) => {
return receivedData.success;
}),
tap((data: boolean) => {console.log("User authenticated", data)}),
catchError(this.handleError)
)
}


However, now that I have updated RxJS to v6.3 I get this error:



ERROR in src/app/login/user.service.ts(50,13): error TS2345: Argument of type 'OperatorFunction<UserVerifyResponse, boolean>' is not assignable to parameter of type 'OperatorFunction<boolean, boolean>'.
Type 'UserVerifyResponse' is not assignable to type 'boolean'.


It bothers me, because I use this approach of mapping API response to an internal class or a primitive (in other place I have a service which uses http.get<T>) and now I wonder if I should force RxJS 6.2 or there is an easy way to migrate to 6.3. I can rewrite all of them as it is described in the answer to the above mentioned post, but I I want to return a boolean value and my approach looks clearer in my opinion.



Any suggestions?










share|improve this question






















  • By this this.http.get<boolean> you're saying that this request will return an Observable emitting booleans. But then you use map<UserVerifyResponse, boolean> where UserVerifyResponse is an object instead of boolean.
    – martin
    Nov 10 at 15:06










  • Because this is what I want the request to return. With RxJS v6.2 I was able to translate the response that I received from the API (of type UserVerifyResponse) to boolean, so finally the http.get would return Observable of type boolean. Why was it acceptable previously and now it is wrong logic?
    – george007
    Nov 10 at 15:23













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a similar case to one described in this post.



I have a user login service, which (among other things) verifies if user's token is still valid. The server's response is defined in an interface:



export interface UserVerifyResponse {
success: boolean
}


My aim was to create an observable that will return a boolean value depending on whether user is verified. This code was working with RxJS v6.2:



authenticate(): Observable<boolean> {
return this.http.get<boolean>(
this.apiUrl+'/verify_user'
).pipe(
map<UserVerifyResponse, boolean>((receivedData: UserVerifyResponse) => {
return receivedData.success;
}),
tap((data: boolean) => {console.log("User authenticated", data)}),
catchError(this.handleError)
)
}


However, now that I have updated RxJS to v6.3 I get this error:



ERROR in src/app/login/user.service.ts(50,13): error TS2345: Argument of type 'OperatorFunction<UserVerifyResponse, boolean>' is not assignable to parameter of type 'OperatorFunction<boolean, boolean>'.
Type 'UserVerifyResponse' is not assignable to type 'boolean'.


It bothers me, because I use this approach of mapping API response to an internal class or a primitive (in other place I have a service which uses http.get<T>) and now I wonder if I should force RxJS 6.2 or there is an easy way to migrate to 6.3. I can rewrite all of them as it is described in the answer to the above mentioned post, but I I want to return a boolean value and my approach looks clearer in my opinion.



Any suggestions?










share|improve this question













I have a similar case to one described in this post.



I have a user login service, which (among other things) verifies if user's token is still valid. The server's response is defined in an interface:



export interface UserVerifyResponse {
success: boolean
}


My aim was to create an observable that will return a boolean value depending on whether user is verified. This code was working with RxJS v6.2:



authenticate(): Observable<boolean> {
return this.http.get<boolean>(
this.apiUrl+'/verify_user'
).pipe(
map<UserVerifyResponse, boolean>((receivedData: UserVerifyResponse) => {
return receivedData.success;
}),
tap((data: boolean) => {console.log("User authenticated", data)}),
catchError(this.handleError)
)
}


However, now that I have updated RxJS to v6.3 I get this error:



ERROR in src/app/login/user.service.ts(50,13): error TS2345: Argument of type 'OperatorFunction<UserVerifyResponse, boolean>' is not assignable to parameter of type 'OperatorFunction<boolean, boolean>'.
Type 'UserVerifyResponse' is not assignable to type 'boolean'.


It bothers me, because I use this approach of mapping API response to an internal class or a primitive (in other place I have a service which uses http.get<T>) and now I wonder if I should force RxJS 6.2 or there is an easy way to migrate to 6.3. I can rewrite all of them as it is described in the answer to the above mentioned post, but I I want to return a boolean value and my approach looks clearer in my opinion.



Any suggestions?







typescript type-conversion rxjs rxjs6 rxjs-pipeable-operators






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 15:00









george007

339212




339212












  • By this this.http.get<boolean> you're saying that this request will return an Observable emitting booleans. But then you use map<UserVerifyResponse, boolean> where UserVerifyResponse is an object instead of boolean.
    – martin
    Nov 10 at 15:06










  • Because this is what I want the request to return. With RxJS v6.2 I was able to translate the response that I received from the API (of type UserVerifyResponse) to boolean, so finally the http.get would return Observable of type boolean. Why was it acceptable previously and now it is wrong logic?
    – george007
    Nov 10 at 15:23


















  • By this this.http.get<boolean> you're saying that this request will return an Observable emitting booleans. But then you use map<UserVerifyResponse, boolean> where UserVerifyResponse is an object instead of boolean.
    – martin
    Nov 10 at 15:06










  • Because this is what I want the request to return. With RxJS v6.2 I was able to translate the response that I received from the API (of type UserVerifyResponse) to boolean, so finally the http.get would return Observable of type boolean. Why was it acceptable previously and now it is wrong logic?
    – george007
    Nov 10 at 15:23
















By this this.http.get<boolean> you're saying that this request will return an Observable emitting booleans. But then you use map<UserVerifyResponse, boolean> where UserVerifyResponse is an object instead of boolean.
– martin
Nov 10 at 15:06




By this this.http.get<boolean> you're saying that this request will return an Observable emitting booleans. But then you use map<UserVerifyResponse, boolean> where UserVerifyResponse is an object instead of boolean.
– martin
Nov 10 at 15:06












Because this is what I want the request to return. With RxJS v6.2 I was able to translate the response that I received from the API (of type UserVerifyResponse) to boolean, so finally the http.get would return Observable of type boolean. Why was it acceptable previously and now it is wrong logic?
– george007
Nov 10 at 15:23




Because this is what I want the request to return. With RxJS v6.2 I was able to translate the response that I received from the API (of type UserVerifyResponse) to boolean, so finally the http.get would return Observable of type boolean. Why was it acceptable previously and now it is wrong logic?
– george007
Nov 10 at 15:23












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Apparently, they have improved the type-checking.



When you wrote this.http.get<boolean>, you are saying "this get is returning an Observable of type boolean", which is not what you mean. The get is returning an Observable of type UserVerifyResponse and you should say so:



authenticate(): Observable<boolean> {
return this.http.get<UserVerifyResponse>(
this.apiUrl+'/verify_user'
).pipe(
map((receivedData) => {
return receivedData.success;
}),
tap((data) => {console.log("User authenticated", data)}),
catchError(this.handleError)
)
}


The pipe alters the Observable from UserVerifyResponse to the boolean that is ultimately returned.



Note that I have deleted most of the typing you had. In general, you should only specify type when:




  • you have to, as is the case with the get() itself, since the TypeScript compiler cannot correctly infer the type, or

  • you are writing a publicly available function, as is the case with authenticate(), since while TypeScript can infer the type, someone reading your code later probably cannot.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240192%2fwhy-map-doesnt-work-after-upgrading-rxjs-to-v6-3%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Apparently, they have improved the type-checking.



    When you wrote this.http.get<boolean>, you are saying "this get is returning an Observable of type boolean", which is not what you mean. The get is returning an Observable of type UserVerifyResponse and you should say so:



    authenticate(): Observable<boolean> {
    return this.http.get<UserVerifyResponse>(
    this.apiUrl+'/verify_user'
    ).pipe(
    map((receivedData) => {
    return receivedData.success;
    }),
    tap((data) => {console.log("User authenticated", data)}),
    catchError(this.handleError)
    )
    }


    The pipe alters the Observable from UserVerifyResponse to the boolean that is ultimately returned.



    Note that I have deleted most of the typing you had. In general, you should only specify type when:




    • you have to, as is the case with the get() itself, since the TypeScript compiler cannot correctly infer the type, or

    • you are writing a publicly available function, as is the case with authenticate(), since while TypeScript can infer the type, someone reading your code later probably cannot.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      Apparently, they have improved the type-checking.



      When you wrote this.http.get<boolean>, you are saying "this get is returning an Observable of type boolean", which is not what you mean. The get is returning an Observable of type UserVerifyResponse and you should say so:



      authenticate(): Observable<boolean> {
      return this.http.get<UserVerifyResponse>(
      this.apiUrl+'/verify_user'
      ).pipe(
      map((receivedData) => {
      return receivedData.success;
      }),
      tap((data) => {console.log("User authenticated", data)}),
      catchError(this.handleError)
      )
      }


      The pipe alters the Observable from UserVerifyResponse to the boolean that is ultimately returned.



      Note that I have deleted most of the typing you had. In general, you should only specify type when:




      • you have to, as is the case with the get() itself, since the TypeScript compiler cannot correctly infer the type, or

      • you are writing a publicly available function, as is the case with authenticate(), since while TypeScript can infer the type, someone reading your code later probably cannot.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Apparently, they have improved the type-checking.



        When you wrote this.http.get<boolean>, you are saying "this get is returning an Observable of type boolean", which is not what you mean. The get is returning an Observable of type UserVerifyResponse and you should say so:



        authenticate(): Observable<boolean> {
        return this.http.get<UserVerifyResponse>(
        this.apiUrl+'/verify_user'
        ).pipe(
        map((receivedData) => {
        return receivedData.success;
        }),
        tap((data) => {console.log("User authenticated", data)}),
        catchError(this.handleError)
        )
        }


        The pipe alters the Observable from UserVerifyResponse to the boolean that is ultimately returned.



        Note that I have deleted most of the typing you had. In general, you should only specify type when:




        • you have to, as is the case with the get() itself, since the TypeScript compiler cannot correctly infer the type, or

        • you are writing a publicly available function, as is the case with authenticate(), since while TypeScript can infer the type, someone reading your code later probably cannot.






        share|improve this answer












        Apparently, they have improved the type-checking.



        When you wrote this.http.get<boolean>, you are saying "this get is returning an Observable of type boolean", which is not what you mean. The get is returning an Observable of type UserVerifyResponse and you should say so:



        authenticate(): Observable<boolean> {
        return this.http.get<UserVerifyResponse>(
        this.apiUrl+'/verify_user'
        ).pipe(
        map((receivedData) => {
        return receivedData.success;
        }),
        tap((data) => {console.log("User authenticated", data)}),
        catchError(this.handleError)
        )
        }


        The pipe alters the Observable from UserVerifyResponse to the boolean that is ultimately returned.



        Note that I have deleted most of the typing you had. In general, you should only specify type when:




        • you have to, as is the case with the get() itself, since the TypeScript compiler cannot correctly infer the type, or

        • you are writing a publicly available function, as is the case with authenticate(), since while TypeScript can infer the type, someone reading your code later probably cannot.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 16:56









        Malvolio

        24k2179107




        24k2179107






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240192%2fwhy-map-doesnt-work-after-upgrading-rxjs-to-v6-3%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            さくらももこ

            13 indicted, 8 arrested in Calif. drug cartel investigation