I am splitting my code into different modules.
In my main.mo I have the following:
import Principal "mo:base/Principal";
import Profile "profile";
actor App {
let users : HashMap.HashMap<Principal, Profile> = HashMap.HashMap<Principal, Profile> (0, Principal.equal, Principal,hash);
//I have a bunch of functions here
}
In profile.mo :
module {
public type Profile = {
fname : Text;
lname : Text;
}
}
The issue that I am facing is that when I import the Profile module that lives in profile.mo I get the following error:
src/app/profile
unbound type Profile
It’s probably because you should prefix with module or re-declare your types.
For example I’ve got in ./types/types.mo
:
import Principal "mo:base/Principal";
module {
public type UserId = Principal;
}
When I want to use it else where like in manager/manager.mo
I redeclare the types to shorten the usages:
import Types "../types/types";
actor Manager {
private type UserId = Types.UserId;
// Then I can use UserId ...
public func something(): async (UserId) {
let userId: UserId = ....
};
But I guess it should work out too without redeclaring but by prefixing with modules:
import Types "../types/types";
actor Manager {
// Then I can use Types.UserId ...
public func something(): async (Types.UserId) {
let userId: Types.UserId = ....
};
1 Like
Got it. I wasnt redeclaring before using it. Thanks @peterparker That fixed it!
1 Like