I have an asynchronous function, returning a promise. Now I want TypeScript to check if I resolve the promises. If ever I missed adding await it should show a warning. How can I do that?
export const getData = async (id: number): Promise<number> => {
return axios.get(
`/api/human/${id}`
);
};
// Should show error as await is missing
console.log(getData(1));
// Should just work
console.log(await getData(2));
Maybe this can not be achieved with Typescript but eslint. Then please help me out how to do that way.
If the only option is no-floating-promises from tslint, this is not helping, as it is deprecated and not used in my code base.
Update: As @son-nguyen pointed out awaiting axios and then casting a promise is redundant. So I removed the await for it.