Hashmap field keys and vals do not exist in type

According the HashMap documentation the module exposes function keys and vals but, when I build I get following error:

storage.store.mo:74.42-74.48: type error [M0072], field keys does not exist in type
{
delete : Text → ();
entries : () → Iter/1<(Text, Asset/1)>;
get : Text → ?Asset/1;
put : (Text, Asset/1) → ();
remove : Text → ?Asset/1;
replace : (Text, Asset/1) → ?Asset/1;
size : () → Nat
}

Likewise, when I try the following in the motoko playground got the same error.

import HashMap "mo:base/HashMap";
import Iter "mo:base/Iter";
import Text "mo:base/Text";

actor Echo {

    private var assets: HashMap.HashMap<Text, Text> = HashMap.HashMap<Text, Text>(
            0, Text.equal, Text.hash,
        );

  // Say the given phase.
  public query func say() : async [Text] {
    let keys: Iter.Iter<Text> = assets.keys(); // <-- same error
    return Iter.toArray(keys);
  };
};

Documentation is incorrect or am I missing something ?

Is there a quick way to get all keys?

1 Like

Got following workaround meanwhile but does not seem that performant :thinking:.

public query func say() : async [Text] {
    let entries: Iter.Iter<(Text, Text)> = assets.entries();
    let keys: Iter.Iter<Text> = Iter.map(entries, func ((key: Text, value: Text)) : Text { key });
    return Iter.toArray(keys);
  };
1 Like

These methods were only added recently, perhaps you need to update your SDK/Motoko installation to have them available.

1 Like

I am on DFX v0.8.1 and can reproduce the error with the Motoko Playground too :man_shrugging:.

Maybe yes with next dfx version but, will wait until issues are solved to try out.

Ah, sorry for that. I guess the playground is behind due to the same issues.

No worries, got a workaround :wink:. I’ll check again next time I upgrade dfx.

Any news on when vals() will be available in Hashmap?

It is missing in dfx 0.8.3. Same for Iter.