Copy constants from C++ to Typescript definition file (openrct2.d.ts) #21160
Unanswered
pfroud
asked this question in
Feature requests
Replies: 2 comments 2 replies
-
Why not use enums? https://www.typescriptlang.org/docs/handbook/enums.html |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think it's a good idea, but I think it needs some thought into how we can prevent the enums from desyncing, because now they will need to be updated in two different spots if changes are needed. Or should we just make enum-string maps for all of them and deprecate the integer fields? Side note: whatever the solution though, the enums should conform to the code style already present openrct2.d.ts. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I noticed the typescript definition file sometimes says to to look at the C++ source. Should I copy constants from C++ into the .d.ts file?
For example:
The definition in Staff.h is:
I think these numbers will never change, so they could easily be add to the .d.ts file.
Simple way:
To use the simple way:
Slightly fancier way:
(The
as const
thing prevents the properties inside the object from being changed.)To use the fancier way:
This could NOT change the plugin API version, it's fully backwards compatible. In this example the
staffType
property would still be anumber
.Beta Was this translation helpful? Give feedback.
All reactions