#Shipping TS enums in JS library
11 messages · Page 1 of 1 (latest)
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
every time i want to reference an enum i have to use (typeof Enum)[keyof typeof Enum] with my current method which sucks
and btw i only use ts to generate types, can i modify that in some way to include enums
from what I can find on d.js monorepo, they seem to use the function in its dedicated file called createEnum in src/util/Enums.js
2 places I can find seems to call that function in Partials.js and Status.js
i know that but im kinda confused as to how they tell that any objects created using this function are enums
ok so the Enums.js is just created to map keys to numbers
for example if they put ready as the first index then Ready's value in the enum will be 0
but that's not what i'm trying to do at all
Mainlibs typings are maintained separately from the js code. There is nothing telling ts that the createEnums function’s return value is also a ts enum. It’s written separately with the same names. For the subpackages those are written in ts and the TS enums get transpiled into js objects by tsc
hmm so can i create a typescript enum in js? can i just copy the compiled code for enums and use that to recreate them in a plain js lib?