Cannot set properties of undefined when extending `container`

Hello! I wanted to create a property entities that holds two properties which would be users and guild of class Entity. Now entities doesn't have any type at all since it'll just be an object to hold users and guild in one. But whenever I run my bot I receive Cannot set properties of undefined (setting 'users') Here's my augments:
declare module '@sapphire/pieces' {
interface Container {
entities: {
users: Entity<UserModel>;
guilds: Entity<GuildModel>;
};
}
}
declare module '@sapphire/pieces' {
interface Container {
entities: {
users: Entity<UserModel>;
guilds: Entity<GuildModel>;
};
}
}
And here's it is being initialized in setup.ts
container.entities.users = new Entity({});
container.entities.guilds = new Entity({});
container.entities.users = new Entity({});
container.entities.guilds = new Entity({});
I tried moving the initialization inside my Client but I get the same error. Perhaps I'm missing something? Thank you for the help!
Solution:
You need to assign .entities, like this:
container.entities = {
users: new Entity({}),
guilds: new Entity({})
};
container.entities = {
users: new Entity({}),
guilds: new Entity({})
};
...
Jump to solution
5 Replies
Solution
kyra
kyra7mo ago
You need to assign .entities, like this:
container.entities = {
users: new Entity({}),
guilds: new Entity({})
};
container.entities = {
users: new Entity({}),
guilds: new Entity({})
};
Dolliwyx
Dolliwyx7mo ago
Ah I see, that's all I have to change, my augments are fine as it is?
kyra
kyra7mo ago
Yup, it is
Dolliwyx
Dolliwyx7mo ago
I see, thank you for the quick response!! peepoLove
Favna
Favna7mo ago
augments are type only, you need to define runtime as well which is what Kyra showed.