I'm making a typescript npm package.
It uses discord.js, but there's two main version of discord.js:
* discord.js 11.5
* discord.js v12.0.0-dev
I'd like my module to support both version. I mean, users can install the version of discord.js they want and the package will use the good code.
For another project, in javascript (without typescript), I use this:
const { version } = require("discord.js");
if(version === "12.0.0-dev"){
// code for v12
} else {
// code for v11
}
and it works perfectly. But, with typescript, it's more complicated, due to typings. Indeed, discord.js typings aren't the same in v11 and in v12, so I can't compile the code with both versions:
const { Guild, version } = require("discord.js");
if(version === "12.0.0-dev"){
Guild.iconURL(); // for v12
} else {
Guild.iconURL; // for v11
}
if the v12 is installed, it will throw iconURL() doesn't exist on Guild and if it's v11, iconURL doesn't exist on Guild.
Is there any way to support both versions in the same package, without creating a branch for each version?