TS1055

error TS1055: Type ‘AxiosPromise‘ is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.

Bad Code ❌

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const sendRequestWithCookie = async (
client: HttpClient,
config: AxiosRequestConfig,
engine: CRUDEngine
): AxiosPromise => {
const cookie: Cookie = await loadExistingCookie(engine);

if (!cookie.isExpired) {
config.headers = config.headers || {};
config.headers['Cookie'] = `zuid=${cookie.zuid}`;
config.withCredentials = true;
}

return client._sendRequest(config);
};

Fixed Code ✔️

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const sendRequestWithCookie = (
client: HttpClient,
config: AxiosRequestConfig,
engine: CRUDEngine
): AxiosPromise => {
return loadExistingCookie(engine).then((cookie: Cookie) => {
if (!cookie.isExpired) {
config.headers = config.headers || {};
config.headers['Cookie'] = `zuid=${cookie.zuid}`;
config.withCredentials = true;
}

return client._sendRequest(config);
});
};