Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): make TVariables default to unknown on Mutation #7433

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions packages/angular-query-experimental/src/inject-mutation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
untracked,
} from '@angular/core'
import {
type DefaultError,
type Mutation,
type MutationCache,
type MutationFilters,
Expand All @@ -22,9 +21,7 @@ import type { Injector, Signal } from '@angular/core'

type MutationStateOptions<TResult = MutationState> = {
filters?: MutationFilters
select?: (
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
) => TResult
select?: (mutation: Mutation) => TResult
}

function getResult<TResult = MutationState>(
Expand All @@ -35,11 +32,7 @@ function getResult<TResult = MutationState>(
.findAll(options.filters)
.map(
(mutation): TResult =>
(options.select
? options.select(
mutation as Mutation<unknown, DefaultError, unknown, unknown>,
)
: mutation.state) as TResult,
(options.select ? options.select(mutation) : mutation.state) as TResult,
)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/query-core/src/hydration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
DefaultError,
MutationKey,
MutationMeta,
MutationOptions,
Expand All @@ -21,7 +22,7 @@ export interface DehydrateOptions {
export interface HydrateOptions {
defaultOptions?: {
queries?: QueryOptions
mutations?: MutationOptions
mutations?: MutationOptions<unknown, DefaultError, unknown, unknown>
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/query-core/src/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface MutationConfig<TData, TError, TVariables, TContext> {
export interface MutationState<
TData = unknown,
TError = DefaultError,
TVariables = void,
TVariables = unknown,
TContext = unknown,
> {
context: TContext | undefined
Expand Down Expand Up @@ -81,7 +81,7 @@ export type Action<TData, TError, TVariables, TContext> =
export class Mutation<
TData = unknown,
TError = DefaultError,
TVariables = void,
TVariables = unknown,
TContext = unknown,
> extends Removable {
state: MutationState<TData, TError, TVariables, TContext>
Expand Down
11 changes: 2 additions & 9 deletions packages/react-query/src/useMutationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as React from 'react'
import { notifyManager, replaceEqualDeep } from '@tanstack/query-core'
import { useQueryClient } from './QueryClientProvider'
import type {
DefaultError,
Mutation,
MutationCache,
MutationFilters,
Expand All @@ -25,9 +24,7 @@ export function useIsMutating(

type MutationStateOptions<TResult = MutationState> = {
filters?: MutationFilters
select?: (
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
) => TResult
select?: (mutation: Mutation) => TResult
}

function getResult<TResult = MutationState>(
Expand All @@ -38,11 +35,7 @@ function getResult<TResult = MutationState>(
.findAll(options.filters)
.map(
(mutation): TResult =>
(options.select
? options.select(
mutation as Mutation<unknown, DefaultError, unknown, unknown>,
)
: mutation.state) as TResult,
(options.select ? options.select(mutation) : mutation.state) as TResult,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ describe('useMutationState', () => {
filters: { status: 'pending' },
}))

expectTypeOf(result()).toEqualTypeOf<
Array<MutationState<unknown, Error, void, unknown>>
>()
expectTypeOf(result()).toEqualTypeOf<Array<MutationState>>()
})
it('should infer with select', () => {
const result = useMutationState(() => ({
Expand Down
11 changes: 2 additions & 9 deletions packages/solid-query/src/useMutationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createEffect, createMemo, createSignal, onCleanup } from 'solid-js'
import { replaceEqualDeep } from '@tanstack/query-core'
import { useQueryClient } from './QueryClientProvider'
import type {
DefaultError,
Mutation,
MutationCache,
MutationFilters,
Expand All @@ -13,9 +12,7 @@ import type { QueryClient } from './QueryClient'

type MutationStateOptions<TResult = MutationState> = {
filters?: MutationFilters
select?: (
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
) => TResult
select?: (mutation: Mutation) => TResult
}

function getResult<TResult = MutationState>(
Expand All @@ -26,11 +23,7 @@ function getResult<TResult = MutationState>(
.findAll(options.filters)
.map(
(mutation): TResult =>
(options.select
? options.select(
mutation as Mutation<unknown, DefaultError, unknown, unknown>,
)
: mutation.state) as TResult,
(options.select ? options.select(mutation) : mutation.state) as TResult,
)
}

Expand Down
11 changes: 2 additions & 9 deletions packages/vue-query/src/useMutationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useQueryClient } from './useQueryClient'
import { cloneDeepUnref } from './utils'
import type { DeepReadonly, Ref } from 'vue-demi'
import type {
DefaultError,
MutationFilters as MF,
Mutation,
MutationState,
Expand Down Expand Up @@ -51,9 +50,7 @@ export function useIsMutating(

export type MutationStateOptions<TResult = MutationState> = {
filters?: MutationFilters
select?: (
mutation: Mutation<unknown, DefaultError, unknown, unknown>,
) => TResult
select?: (mutation: Mutation) => TResult
}

function getResult<TResult = MutationState>(
Expand All @@ -64,11 +61,7 @@ function getResult<TResult = MutationState>(
.findAll(options.filters)
.map(
(mutation): TResult =>
(options.select
? options.select(
mutation as Mutation<unknown, DefaultError, unknown, unknown>,
)
: mutation.state) as TResult,
(options.select ? options.select(mutation) : mutation.state) as TResult,
)
}

Expand Down
Loading