During the implementation of client-side server communication, I encountered a particular challenge: How can I store a reference to an interface in a variable?
I have defined an interface that contains all the details related to a specific RESTful backend call:
export interface IEndpoint {
path: string,
method: HTTP_METHOD,
data: any,
response: any
}
To create instances of this interface (ISomeInterface and IAnotherInterface are the interfaces I want to reference later), I do the following:
export const GET_TEST: IEndpoint = {
path: 'api/test',
method: HTTP_METHOD.GET,
data: <ISomeInterface>{},
response: <IAnotherInterface>{}
};
The objective is to use the data and response fields as type references in a Promise (where meta is an instance of IEndpoint):
new Promise<meta.response>((resolve) => {
...
});
The issue arises when trying to extract the type/interface previously assigned for the callback type of the Promise (meta.response).