Typescript does not recognize undefined return value of non-lazy imported pinia colada loader. #633
-
Am not sure if I am doing something wrong but according to the documentation:
A loader which looks like this: const useMetadataData = defineColadaLoader({
query: () => graphQLClient.request(getMetadataDocument),
key: ['metadata'],
staleTime: Infinity
}) and ist exported from a page component like this: // /pages/metadata/[id].vue
<script lang="ts">
import useMetadataData from '@/loaders/use-metadata-data'
export { useMetadataData }
<script> to then be finally imported into a component like this: import { useMetadataData } from '@/pages/metadata/[id].vue'
const { data } = useMetadataData() is not properly recognized by typescript. Note that the component in question is not a child of the page component where the loader is exported. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It sounds like the component that consumes the data loader is used and mounted before the navigation takes places and therefore before the data loading |
Beta Was this translation helpful? Give feedback.
It’s not about the route component mounting first. It’s about the navigation happening and finishing before any component using the data loader (including the route component) mounts
it works too, but you should mark the loader as lazy