• shape_warrior_t@programming.dev
    link
    fedilink
    English
    arrow-up
    29
    ·
    2 days ago

    I would certainly rather see this than {isAdmin: bool; isLoggedIn: bool}. With boolean | null, at least illegal states are unrepresentable… even if the legal states are represented in an… interesting way.

      • shape_warrior_t@programming.dev
        link
        fedilink
        English
        arrow-up
        6
        ·
        edit-2
        1 day ago

        I was thinking of the three legal states as:

        • not logged in (null or {isAdmin: false, isLoggedIn: false})
        • logged in as non-admin (false or {isAdmin: false, isLoggedIn: true})
        • logged in as admin (true or {isAdmin: true, isLoggedIn: true})

        which leaves {isAdmin: true, isLoggedIn: false} as an invalid, nonsensical state. (How would you know the user’s an admin if they’re not logged in?) Of course, in a different context, all four states could potentially be distinctly meaningful.