eslachance/enmap

Enmap with typescript

Closed this issue ยท 10 comments

Hi

I started with refactoring of my discord bot from js to typescript.
How can i use enmap with it?
It tells that value are not exists and doesn't allow me to use it as before

Hi @CrownlessX, enmap has typings in index.d.ts and so it should work, it would help if you could share the error

Thank you quick response!

@dan-online

I'm using it with js as:
client.guildsSettings = new Enmap({
name: "guildsSettings",
fetchAll: false,
autoFetch: true,
cloneLevel: 'deep'
});

But for typescript(newb) got:
Property 'guildsSettings' does not exist on type 'Client'

Hi @CrownlessX, enmap has typings in index.d.ts and so it should work, it would help if you could share the error

I'm pretty sure that the typings need a good updating/refactoring, but I have been too busy and lack the incentive to do so.

Probably, I'm just too bad with understanding how it does work.
I don't need to "stick" it to a client, i suppose, and use it as solo obj

Actually @RealShadowNova the typings aren't the problem, because "client" is a Discord constructor it's not made to have "guildsSettings", I believe you have to add the type as being enmap

Thank you quick response!

@dan-online

I'm using it with js as:
client.guildsSettings = new Enmap({
name: "guildsSettings",
fetchAll: false,
autoFetch: true,
cloneLevel: 'deep'
});

But for typescript(newb) got:
Property 'guildsSettings' does not exist on type 'Client'

The solution to this is augmentation. You can read up on it here.

Until then, somewhere you can stick this:

declare module "discord.js" {
 interface Client {
   guildSettings: Enmap
 }
}

@RealShadowNova
Great!
Will try to!
Thank you a lot!

Closing as this seems to be resolved - if you still need assistance, please don't hesitate to reopen a ticket or join our Discord!

@RealShadowNova
Great!
Will try to!
Thank you a lot!

The most efficient solution is to add typings/Augments.d.ts to your project with the above code, and making your own class Client extends DJSClient.

@RealShadowNova
Great!
Will try to!
Thank you a lot!

The most efficient solution is to add typings/Augments.d.ts to your project with the above code, and making your own class Client extends DJSClient.

I know, literally discussed in the Discord server. Just resolving the issue not making it the best for them.