I am currently dealing with a scenario where I have a constant requestBody object being defined. It contains various properties like clientId, orderingId, receivedSignatureFlag, saturdayDeliveryFlag, and so on.
const requestBody: RequestBody = {
clientId: clientId,
orderingId: 113875599,
receivedSignatureFlag: 'N',
saturdayDeliveryFlag: 'N',
deliveryMethodOptionCode: 'USPS',
orderItemsList: [
{
itemCode: 'A123'
transferCode: 'MAIL',
specialHandling: 'N',
deliveryExternalFlag: 'Y',
orderQuantityAmount: 1,
}
]
};
To make the code more structured and maintainable, I decided to create an enum called ReqBodyEnum to hold all the string values that are used in the requestBody object.
export enum ReqBodyEnum {
RCVD_FLAG = 'N',
SAT_DELIVERY_FLAG = 'N',
}
Now, here comes the issue. When trying to set the receivedSignatureFlag property to the value from the enum, it doesn't seem to work as expected.
receivedSignatureFlag:ReqBodyEnum[ReqBodyEnum.RCVD_FLAG] -> this isnt working.
I also attempted another approach:
receivedSignatureFlag:ReqBodyEnum.RCVD_FLAG
However, none of these methods provided the desired outcome. So, I'm looking for suggestions on how to correctly set the value from an enum in this context. Any ideas or best practices would be greatly appreciated!