Currently, I am utilizing the API of Slack and encountering situations where I send JSON requests containing strings that return as property names later on.
I want to create an interface where I can send one of its property names as a string and receive the returning object with correct typing without relying on "magic strings" or constants that need to stay synchronized with the interface.
Here's a quick example:
// Sending out this request to Slack
const request = {
actionId: "specialProperty"
};
// Later, Slack might return this object
const incomingWebhook = {
specialProperty: "Value I want to read"
}
I can easily define typing for this using an interface
interface SpecialPropertyInterface {
specialProperty: string;
}
My concern is that this interface is tied to the string I send out.
Is there a way for me to extract the key/property "specialProperty" from my SpecialPropertyInterface as a string?