Issue with such approach that you cannot use ResultCodeMap as function argument to restrict argument values. You need to write something like
function sendResultCode(code: shared_1.Historical.ResultCodeMap[keyof shared_1.Historical.ResultCodeMap]): void {
...
}
Then you will get compile time checks for input value. Such approach works but not user-friendly. I suggest generating alias for types like shared_1.Historical.ResultCodeMap[keyof shared_1.Historical.ResultCodeMap] and give it name like original enum const.
Type alias shall be
export type ResultCode = ResultCodeMap[keyof ResultCodeMap];
So function and invocation code become
function sendResultCode(code: shared_1.Historical.ResultCode): void {
...
}
...
sendResultCode(shared_1.Historical.ResultCode.RESULT_CODE_SUCCESS);
Such function and call signature naturally mimics regular enum usage.
Changes
Currently tool generates interface and const to access enum-like values.
Issue with such approach that you cannot use
ResultCodeMap
as function argument to restrict argument values. You need to write something likeThen you will get compile time checks for input value. Such approach works but not user-friendly. I suggest generating alias for types like
shared_1.Historical.ResultCodeMap[keyof shared_1.Historical.ResultCodeMap]
and give it name like original enum const.Type alias shall be
So function and invocation code become
Such function and call signature naturally mimics regular enum usage.
Verification
Tested in my own project.