I have a problem with Typescript const enum
s in .svelte
files in my project. I have a type definition file, shared between multiple parts of my project. There are two namespaces (Events and Procedures) in here, each consists of 3-4 enums with event/procedure names, one for every part of the project.
So the structure looks like this.
namespace Shared {
namespace Events {
const enum Server {
BC = "DF",
...
}
const enum Client {
AB = "DB",
...
},
const enum SomethingElse {
...
}
...
},
namespace Procedures {
...
}
}
This approach works great for every part of the project -- except svelte files.
So if I'm trying to use Shared.Events.Server.BC
in any other environment (including .ts files of the same "part"), I get DF
. If I'm trying to use it in .svelte files, after bundling, in the resulting .js file, it stays untouched: Shared.Events.Server.BC
. (And since there is no Shared in the runtime, it's not working).
I can't switch to plain enum
s due to the technical limitations of other parts of the project.
For bundling I'm using Rollup, svelte-preprocess and @rollup/plugin-typescript with a pretty much standard configuration:
svelte({
dev: isDevelopment,
extensions: [".svelte"],
preprocess: sveltePreprocessor(),
emitCss: true,
css: function(css) {
css.write(path.join(dest, 'bundle.css' ));
},
onwarn: (warning, handler) => {
if (warning.code.indexOf("a11y") !== -1) return;
handler(warning);
}
}),
typescript({ typeRoots: ["./types/", "./node_modules/@types/"] }),
resolve(),
commonjs({ include: "node_modules/**", extensions: [".js", ".ts"] }),
...