Issue
I have a cloud function that takes an email and returns the user info, including the uid.
The function is declared like this:
const getUserByEmail = httpsCallable(functions, 'getUserByEmail')
const user = await getUserByEmail({
email: email,
})
But when I try to read "user.data.id" typescript yells at me because:
"Object is of type 'unknown'.ts(2571) (property)
HttpsCallableResult.data: unknown Data returned from callable function.
What am I missing?
edit: of course I tried "user: any" and TS is happy, but it's not a great solution.
Solution
httpsCallable needs type info.
httpsCallable<RequestData, ResponseData>
const getUserByEmail = httpsCallable<{email: string}, {
user: {
data: {
id: string,
}
}
}>(functions, 'getUserByEmail');
const { data } = await getUserByEmail({
email: email,
});
const userId = data.user.data.id;
Answered By - Isamu Arimoto
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.