MISC: Change how enums are exposed in NetscriptDefinitions.d.ts #1998
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We expose enums with
declare enum
for typing (technically, the reason is more complicated, but let's simplify it here) andns.enums
for runtime data. Some players assume that they can access those enums at runtime by using those declared enums, but those enums do not exist at runtime like they think. For example: #1198. We can resolve this problem by changing how we expose enums to players in that file.At first, there are tons of discussions about TS enum and its alternatives on the Discord server and everywhere on the Internet. At least, please read Enums and some old discussions on the Discord server (search "enum" and check "Old").
Scope of this change:
declare enum
inNetscriptDefinitions.d.ts
.Things to remember:
ns.enums.Something
must have proper types and work as normal.LocationName | ${LocationName}
.api-extractor
.This PR won't touch internal enums. Changing all internal enums to
as const
objects is a bag of worms. It needs to be done in another PR.This PR is in the draft state now. After we agree on how to do it, I'll expand the change to other enums and run
npm run doc
.