Angular Tanstack Query ExplicitType for injectQuery()

Discussão em 'Angular' iniciado por Eternal Sunshine, Outubro 15, 2024.

  1. I am trying to use Tan stack Query in Angular And my VS Code has been complaining that I have to explicitly mention type for result of the inject Query as CreateQueryResult<Data, Error>; where as non of the example in their documentation uses any explicit types. for example in the docs:

    class ServiceOrComponent {
    filter = signal('')

    todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
    }))
    }



    where as What I have is whihc doesnt seem right for some reason. My question is that Do I have to have the type for every injectQuery? as CreateQueryResult

    class ServiceOrComponent {
    filter = signal('')

    todosQuery: CreateQueryResult<Data, Error>; = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
    }))
    }

    Continue reading...

Compartilhe esta Página