Currently working with Slacks API and there are instances where I send JSON requests with strings, and these strings return at a later point as property names.
I would like have an interface and send one of its property names as a string. And then have the returning object correctly typed. I dont want to have to deal with "magic strings" or constants that I have to keep in sync with the interface.
Quick example:
// This is the request I send out to Slack
const request = {
actionId: "specialProperty"
};
// And Slack might give me this object at a later point
const incomingWebhook = {
specialProperty: "Value I want to read"
}
I can fairly easily get typing for this with an interface
interface SpecialPropertyInterface {
specialProperty: string;
}
My issue is that this interface is bound to the string that I send out.
Is there a way for me to get the key/property "specialProperty" from my SpecialPropertyInterface as a string?