So, this is weird, and there's probably a better way to do this, but is there a way to type an enum as another enum?
Basically, I have a large client library (discord.js) with some enums that I'm referencing in my documentation package which is imported into both my client app and my web app. I want to use those enums from discord.js in the documentation library, but I don't want to have to import that whole client-side node package into my web app to do so.
My first thought is to redeclare the enums myself, and type them from an import type with the source enum, but I can't seem to figure out how to make that work. However, I can't figure out syntax for it. This sort of thing doesn't work:
import type { ApplicationCommandOptionType as ApplicationCommandOptionTypeSource } from 'discord.js';
enum ApplicationCommandOptionType {
Subcommand = 1,
SubcommandGroup = 2,
String = 3,
Integer = 4,
Boolean = 5,
User = 6,
Channel = 7,
Role = 8,
Mentionable = 9,
Number = 10,
Attachment = 11
}
const test = ApplicationCommandOptionType as ApplicationCommandOptionTypeSource; //Conversion of type 'typeof ApplicationCommandOptionType' to type 'ApplicationCommandOptionType' may be a mistake because neither type sufficiently overlaps with the other.
Is there a better way to accomplish this? I want to maintain the type safety with these enums while only importing the types from the discord.js library.