LiteMol icon indicating copy to clipboard operation
LiteMol copied to clipboard

Cannot access value defined by `const enum` internally

Open xuzuodong opened this issue 2 years ago • 3 comments

In my project, after import LiteMol as an external library, I want to access value internally defined by const enum, i.e. LiteMol.Visualization.Selection.Action.xxx, but it seems not possible due to the pitfalls described here.

So, instead of code like this:

model.applySelection([1, 2, 3], LiteMol.Visualization.Selection.Action.Select)

I have to use literal value as a workaround:

model.applySelection([1, 2, 3], 1)

Is there any better solutions?

xuzuodong avatar Apr 25 '22 02:04 xuzuodong

I am afraid using the const value is the only option here (or copy pasting the entire enum to your code and using it there).

dsehnal avatar Apr 25 '22 06:04 dsehnal

Thanks for your feedback!

For now I will just use const value, but I think this issue is possible to be solved by rebuilding the whole package with the compiler option preserveConstEnums set to true. So maybe in the future I can create a PR?

xuzuodong avatar Apr 25 '22 06:04 xuzuodong

Yes, although I think there will be some more issues with namespaces and the isolated modules. The const enums aren't used that much (and I wasn't aware of the drawbacks when I coded this).

Btw if you are just integrating a new viewer, I would recommend you use https://molstar.org instead.

dsehnal avatar Apr 25 '22 07:04 dsehnal