timotejroiko / discord.js-light

All the power of discord.js, zero caching. This library modifies discord.js's internal classes and functions in order to give you full control over its caching behaviour.
Apache License 2.0
292 stars 29 forks source link

Fix exporting from within module #12

Closed KevinNovak closed 4 years ago

KevinNovak commented 4 years ago

Fix for:

Exports and export assignments are not permitted in module augmentations.

image

timotejroiko commented 4 years ago

could you test it like this? (i dont have a ts compiler, so im just going off of what vscode's intelisense shows)

export * from "discord.js"

declare module "discord.js-light" {
    import * as Discord from "discord.js"
    interface ClientOptions {
        cacheChannels?:boolean,
        cacheGuilds?:boolean,
        cachePresences?:boolean,
        cacheRoles?:boolean,
        cacheOverwrites?:boolean,
        cacheEmojis?:boolean
    }
    interface ClientEvents {
        rest:[{path:string,method:string,response:Promise<Buffer>}],
        shardConnect:[number,Discord.Collection<Discord.Snowflake,Discord.Guild>],
        guildEmojisUpdate:[Discord.Collection<Discord.Snowflake,Discord.GuildEmoji>]
    }
    class Client extends Discord.Client {
        public sweepUsers(lifetime: number): void;
        public sweepChannels(lifetime: number): void;
    }
}
KevinNovak commented 4 years ago

Here is what happens with that code when I run tsc (the typescript compiler): image

You can install typescript compiler as well with: npm install -g typescript

Then you should have the tsc command.

timotejroiko commented 4 years ago

how about this. No errors when running tsc, but im not sure if i ran it right

import * as Discord from "discord.js"
export * from "discord.js"

export class Client extends Discord.Client {
    public sweepUsers(lifetime: number): void;
    public sweepChannels(lifetime: number): void;
}

declare module "discord.js-light" {
    interface ClientOptions {
        cacheChannels?:boolean,
        cacheGuilds?:boolean,
        cachePresences?:boolean,
        cacheRoles?:boolean,
        cacheOverwrites?:boolean,
        cacheEmojis?:boolean
    }
    interface ClientEvents {
        rest:[{path:string,method:string,response:Promise<Buffer>}],
        shardConnect:[number,Discord.Collection<Discord.Snowflake,Discord.Guild>],
        guildEmojisUpdate:[Discord.Collection<Discord.Snowflake,Discord.GuildEmoji>]
    }
}
KevinNovak commented 4 years ago

With this code, I no longer need to import from discord.js, everything can be imported from discord.js-light: image image

This includes the extra client options combined with the original options from discord.js: image

All compiles good. Looks great!

timotejroiko commented 4 years ago

Awesome. Add it to you PR and i'll merge

KevinNovak commented 4 years ago

Added. Thanks!