Angular/NGXS sample code - cannot get reference of the parameter input









up vote
1
down vote

favorite












I'm trying to implement the login as mentioned here.



https://ngxs.gitbook.io/ngxs/recipes/authentication



 @Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))



But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.



enter image description here










share|improve this question





















  • Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
    – Rafael
    Nov 10 at 3:06










  • Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
    – Aby
    Nov 14 at 9:14











  • Awesome, I'm glad to hear that. The fix was merged in #653
    – Rafael
    Nov 14 at 16:35














up vote
1
down vote

favorite












I'm trying to implement the login as mentioned here.



https://ngxs.gitbook.io/ngxs/recipes/authentication



 @Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))



But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.



enter image description here










share|improve this question





















  • Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
    – Rafael
    Nov 10 at 3:06










  • Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
    – Aby
    Nov 14 at 9:14











  • Awesome, I'm glad to hear that. The fix was merged in #653
    – Rafael
    Nov 14 at 16:35












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to implement the login as mentioned here.



https://ngxs.gitbook.io/ngxs/recipes/authentication



 @Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))



But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.



enter image description here










share|improve this question













I'm trying to implement the login as mentioned here.



https://ngxs.gitbook.io/ngxs/recipes/authentication



 @Action(Login)
login( patchState : StateContext<AuthStateModel>, payload: username : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username );
))



But I'm unable to get the reference of 'payload' as shown in the sample, instead I get the following error. Any help appreciated ! I also wanted to know what ' payload: username ' would mean in the input parameters of the function.



enter image description here







angular angular6 rxjs6 ngxs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 23:40









Aby

1,6461814




1,6461814











  • Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
    – Rafael
    Nov 10 at 3:06










  • Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
    – Aby
    Nov 14 at 9:14











  • Awesome, I'm glad to hear that. The fix was merged in #653
    – Rafael
    Nov 14 at 16:35
















  • Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
    – Rafael
    Nov 10 at 3:06










  • Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
    – Aby
    Nov 14 at 9:14











  • Awesome, I'm glad to hear that. The fix was merged in #653
    – Rafael
    Nov 14 at 16:35















Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06




Aby, did my answer shed light on your issue? I've explained the object destructuring, identified the error, and showed the solution. Did you get past this issue?
– Rafael
Nov 10 at 3:06












Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14





Yes, absolutely Rafael. Thanks for your time !! keep up the good job.
– Aby
Nov 14 at 9:14













Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35




Awesome, I'm glad to hear that. The fix was merged in #653
– Rafael
Nov 14 at 16:35












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










This is an error in the documentation.



Look here:



export class Login 
static readonly type = '[Auth] Login';
constructor(public payload: username: string, password: string )



and here:



login( patchState : StateContext<AuthStateModel>, payload: username : Login) {


This is a destructure mistake and needs to be:



@Action(Login)
login( patchState : StateContext<AuthStateModel>, payload : Login)
return this.authService.login(payload).pipe(tap((result: token: string ) =>
patchState( token, username: payload.username );
))



This destructures Login's payload and then reference username via payload.username.



Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.



Git Blame authentication.md



What Is Destructuring?



payload: username is Destructuring assignment
. In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login(), it means, "I am only interested in username (which is wrong as state above).



I hope this helps!



UPDATE:



This fix has been merged in #653.



Just to clarify:






let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload: username = a;//unwraps payload.username
console.log(username);//works
console.log(payload);//error





Fix:






let a = payload: username: first: 'rafael', last: 'cepeda' ;
let payload = a;//unwraps payload
console.log(payload.username);//works
console.log(payload);//works








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%2f53234647%2fangular-ngxs-sample-code-cannot-get-reference-of-the-parameter-input%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
    1
    down vote



    accepted










    This is an error in the documentation.



    Look here:



    export class Login 
    static readonly type = '[Auth] Login';
    constructor(public payload: username: string, password: string )



    and here:



    login( patchState : StateContext<AuthStateModel>, payload: username : Login) {


    This is a destructure mistake and needs to be:



    @Action(Login)
    login( patchState : StateContext<AuthStateModel>, payload : Login)
    return this.authService.login(payload).pipe(tap((result: token: string ) =>
    patchState( token, username: payload.username );
    ))



    This destructures Login's payload and then reference username via payload.username.



    Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.



    Git Blame authentication.md



    What Is Destructuring?



    payload: username is Destructuring assignment
    . In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login(), it means, "I am only interested in username (which is wrong as state above).



    I hope this helps!



    UPDATE:



    This fix has been merged in #653.



    Just to clarify:






    let a = payload: username: first: 'rafael', last: 'cepeda' ;
    let payload: username = a;//unwraps payload.username
    console.log(username);//works
    console.log(payload);//error





    Fix:






    let a = payload: username: first: 'rafael', last: 'cepeda' ;
    let payload = a;//unwraps payload
    console.log(payload.username);//works
    console.log(payload);//works








    share|improve this answer


























      up vote
      1
      down vote



      accepted










      This is an error in the documentation.



      Look here:



      export class Login 
      static readonly type = '[Auth] Login';
      constructor(public payload: username: string, password: string )



      and here:



      login( patchState : StateContext<AuthStateModel>, payload: username : Login) {


      This is a destructure mistake and needs to be:



      @Action(Login)
      login( patchState : StateContext<AuthStateModel>, payload : Login)
      return this.authService.login(payload).pipe(tap((result: token: string ) =>
      patchState( token, username: payload.username );
      ))



      This destructures Login's payload and then reference username via payload.username.



      Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.



      Git Blame authentication.md



      What Is Destructuring?



      payload: username is Destructuring assignment
      . In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login(), it means, "I am only interested in username (which is wrong as state above).



      I hope this helps!



      UPDATE:



      This fix has been merged in #653.



      Just to clarify:






      let a = payload: username: first: 'rafael', last: 'cepeda' ;
      let payload: username = a;//unwraps payload.username
      console.log(username);//works
      console.log(payload);//error





      Fix:






      let a = payload: username: first: 'rafael', last: 'cepeda' ;
      let payload = a;//unwraps payload
      console.log(payload.username);//works
      console.log(payload);//works








      share|improve this answer
























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        This is an error in the documentation.



        Look here:



        export class Login 
        static readonly type = '[Auth] Login';
        constructor(public payload: username: string, password: string )



        and here:



        login( patchState : StateContext<AuthStateModel>, payload: username : Login) {


        This is a destructure mistake and needs to be:



        @Action(Login)
        login( patchState : StateContext<AuthStateModel>, payload : Login)
        return this.authService.login(payload).pipe(tap((result: token: string ) =>
        patchState( token, username: payload.username );
        ))



        This destructures Login's payload and then reference username via payload.username.



        Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.



        Git Blame authentication.md



        What Is Destructuring?



        payload: username is Destructuring assignment
        . In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login(), it means, "I am only interested in username (which is wrong as state above).



        I hope this helps!



        UPDATE:



        This fix has been merged in #653.



        Just to clarify:






        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload: username = a;//unwraps payload.username
        console.log(username);//works
        console.log(payload);//error





        Fix:






        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload = a;//unwraps payload
        console.log(payload.username);//works
        console.log(payload);//works








        share|improve this answer














        This is an error in the documentation.



        Look here:



        export class Login 
        static readonly type = '[Auth] Login';
        constructor(public payload: username: string, password: string )



        and here:



        login( patchState : StateContext<AuthStateModel>, payload: username : Login) {


        This is a destructure mistake and needs to be:



        @Action(Login)
        login( patchState : StateContext<AuthStateModel>, payload : Login)
        return this.authService.login(payload).pipe(tap((result: token: string ) =>
        patchState( token, username: payload.username );
        ))



        This destructures Login's payload and then reference username via payload.username.



        Credentials are sent upstream and a token is returned downstream. The AuthStateModel is patched via the StateContext.



        Git Blame authentication.md



        What Is Destructuring?



        payload: username is Destructuring assignment
        . In the context of a function parameter, it means, "in this object, I am interested in these properties." Looking at login(), it means, "I am only interested in username (which is wrong as state above).



        I hope this helps!



        UPDATE:



        This fix has been merged in #653.



        Just to clarify:






        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload: username = a;//unwraps payload.username
        console.log(username);//works
        console.log(payload);//error





        Fix:






        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload = a;//unwraps payload
        console.log(payload.username);//works
        console.log(payload);//works








        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload: username = a;//unwraps payload.username
        console.log(username);//works
        console.log(payload);//error





        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload: username = a;//unwraps payload.username
        console.log(username);//works
        console.log(payload);//error





        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload = a;//unwraps payload
        console.log(payload.username);//works
        console.log(payload);//works





        let a = payload: username: first: 'rafael', last: 'cepeda' ;
        let payload = a;//unwraps payload
        console.log(payload.username);//works
        console.log(payload);//works






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 14 at 16:34

























        answered Nov 9 at 23:50









        Rafael

        4,30872037




        4,30872037



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234647%2fangular-ngxs-sample-code-cannot-get-reference-of-the-parameter-input%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

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo