I need help converting the following JavaScript code to TypeScript. I keep running into an error message that says
Expected to return a value at the end of async arrow function
. Can someone help me figure out what's wrong with this code?
export const loginUser = createAsyncThunk(
'users/login',
async ({ email, password }, thunkAPI) : Promise<any> => {
try {
const response = await fetch(
'https://mock-user-auth-server.herokuapp.com/api/v1/auth',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
password,
}),
}
);
const data = await response.json();
console.log('response', data);
if (response.status === 200) {
localStorage.setItem('token', data.token);
return data;
}
return thunkAPI.rejectWithValue(data);
} catch (e) {
console.log('Error', e.response.data);
thunkAPI.rejectWithValue(e.response.data);
}
}
);