How to read a variant object from javascript/PocketIC

I am using PocketIC on javascript to test my canister. Some of my canister methods return a variant. How can I decode the variant from my javascript test code?

Actor code:

Actor {
    public type testtype = {
        #A: Int;
        #B: Text;
    };

    public shared(msg) func testme(): async testtype {
        return #A(2);
    };

};

typescript code:

...
if ('A' in aux) {
      console.log(aux.A);
    };
1 Like

Yes exactly, TypeScript type guards are your friend when it comes to variants.

1 Like