I am trying to declare the type of return data in a function. Here’s the function:
export const getCurrentUserData = async (): User => {
const value = await storage.getItem('currentSite');
if (value === null) {
return '';
} else {
const getuserData = JSON.parse(value)
const userData = {
email: getuserData.userData.email,
id: getuserData.userData.id,
name: getuserData.userData.name,
userKey: getuserData.userData.userKey,
userRole: getuserData.userData.userRole,
photo: getuserData.userData.photo,
}
return userData;
}
}
Here’s my data type:
export type User = {
email: string,
id: string,
name: string,
userKey: string,
userRole: string,
photo: string,
}
Am i doing these the right way? Because it shows the error: 'Type 'User' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor '
2
Answers
You need to include Promise in the signature like so:
Try this code
};