I have this line of code which is a wrapper function even though it works fine,
const to = (promise: any) => promise.then((data: any) => data).catch((err: any) => err);
but eslint is prompting the unexpected any error, if i do not include eslint-disable-next-line
ESLint: Unexpected any. Specify a different type.(@typescript-eslint/no-explicit-any)
the function wrapper to()
can be used to wrap different login methods for example this function,
const loginWithEmail = async (email:string, password:string) => new Promise((reject) => {
const firebase = getFirebase();
firebase.login({
email,
password,
}).catch((error) => {
reject(error);
return error.message;
});
});
and the end result is placed inside a React Component where it will get the err message and place it into a hook to be displayed.
const handleEmailLogin = async () => {
const err = await to(loginWithEmail(email, password));
setEmailLoginError(err.message);
};
i was wondering if there's a better way to define the function to()
without relying on the type any
?