How to type query result? #167
-
Hello, // I have a function that returns the user
export const getUser = () => {
return reactive(useQuery("user", () => strapi.fetchUser()));
};
// and i know the structure of the user data
export type UsersPermissionsUserEntity = {
__typename?: 'UsersPermissionsUserEntity';
id?: Maybe<Scalars['ID']>;
attributes?: Maybe<UsersPermissionsUser>;
};
// I also know the structure of the Error
export type Error = {
__typename?: 'Error';
code: Scalars['String'];
message?: Maybe<Scalars['String']>;
}; // In my component I do this <script setup>
const user = getUser()
</script>
<template>
<Loader v-if="user.isLoading" /> <!-- unrelated -->
<p v-if="user.isSuccess">hello {{ user.data.attributes.username }}!</p>
<template> Is there a way for me to tell typescript that Type '{ readonly data: undefined; readonly error: null; readonly isError: false; readonly isIdle: true; readonly isLoading: false; readonly isLoadingError: false; readonly isRefetchError: false; ... 14 more ...; suspense: () => Promise<...>; }' is not assignable to type 'UseQueryReturnType<UsersPermissionsUserEntity, Error, QueryObserverResult<UsersPermissionsUserEntity, Error>>'. Is there a way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Try |
Beta Was this translation helpful? Give feedback.
Try
useQuery<UsersPermissionsUserEntity, Error>(...)