Replies: 3 comments
-
I think this does work at runtime and is only a typescript error? non-infinite queries and mutations both support type narrowing. For example on @Component({
// ...
template: `
@if (query.isSuccess()) {
@let data = query.data();
// ^? data: number
}
`,
})
class MyComponent {
query = injectQuery(() => ({
queryKey: ['test'],
queryFn: () => Promise.resolve(5),
}))
} However, this is still missing on infinite queries and should be added to the Angular adapter's types. As a workaround for now you can use @if (projectsInfiniteQuery.data()?.pages) {
@let pages = projectsInfiniteQuery.data()!.pages;
@for (page of pages; track $index) {
<!-- pages is not potentially undefined -->
}
} |
Beta Was this translation helpful? Give feedback.
-
@arnoud-dv sadly it doesn't work on runtime, as the Do you think it would be possible for you to do an stackblitz example of a mock implementation where I can get inspected from ? |
Beta Was this translation helpful? Give feedback.
-
https://tanstack.com/query/latest/docs/framework/angular/examples/infinite-query-with-max-pages I added issue #8984 for the missing type narrowing on infinite queries on Angular. |
Beta Was this translation helpful? Give feedback.
-
I wanted to implement the
infinitQuery
with the angular version of TanStack.So i tried to follow the Guideline, and I think I should be correct here
projects.service.ts
projects.component.ts
projects.component.html
But the project is, that
.data()
is always undefined.My initial though was, that this is empty because the API is returning
Project[]
and should return{ pages: Project[]}
.So I've resolved it as
pages
, but it is also not working.I'm a bit lost and would welcome any helps :)
Cheers
Beta Was this translation helpful? Give feedback.
All reactions