Skip to content

Commit

Permalink
fix(angular-query): fix type of isSuccess, isError, isPending, isIdle…
Browse files Browse the repository at this point in the history
… on mutation result (#7923)

* fix(angular-query): fix type of isSuccess, isError, isPending, isIdle

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
divdavem and autofix-ci[bot] authored Aug 29, 2024
1 parent 189e0c5 commit eee80af
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ import type { ThrowOnError } from '@tanstack/query-core';
// @public (undocumented)
export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> {
// (undocumented)
isError: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TContext>>;
isError: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TContext>>>;
// (undocumented)
isIdle: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>>;
isIdle: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>>>;
// (undocumented)
isPending: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TContext>>;
isPending: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TContext>>>;
// Warning: (ae-forgotten-export) The symbol "SignalFunction" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CreateStatusBasedMutationResult" needs to be exported by the entry point index.d.ts
//
// (undocumented)
isSuccess: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TContext>>;
isSuccess: SignalFunction<(this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TContext>>>;
}

// @public (undocumented)
Expand Down
11 changes: 9 additions & 2 deletions packages/angular-query-experimental/src/__tests__/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type InputSignal, isSignal, untracked } from '@angular/core'
import {
type InputSignal,
type Signal,
isSignal,
untracked,
} from '@angular/core'
import { SIGNAL, signalSetFn } from '@angular/core/primitives/signals'
import type { ComponentFixture } from '@angular/core/testing'

Expand Down Expand Up @@ -86,7 +91,9 @@ function evaluateSignals<T extends Record<string, any>>(

export const expectSignals = <T extends Record<string, any>>(
obj: T,
expected: Partial<{ [K in keyof T]: ReturnType<T[K]> }>,
expected: Partial<{
[K in keyof T]: T[K] extends Signal<any> ? ReturnType<T[K]> : never
}>,
): void => {
expect(evaluateSignals(obj)).toMatchObject(expected)
}
Expand Down
93 changes: 55 additions & 38 deletions packages/angular-query-experimental/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
QueryObserverOptions,
QueryObserverResult,
} from '@tanstack/query-core'
import type { Signal } from '@angular/core'
import type { MapToSignals } from './signal-proxy'

/**
Expand Down Expand Up @@ -221,6 +222,8 @@ type CreateStatusBasedMutationResult<
{ status: TStatus }
>

type SignalFunction<T extends () => any> = T & Signal<ReturnType<T>>

/**
* @public
*/
Expand All @@ -230,59 +233,73 @@ export interface BaseMutationNarrowing<
TVariables = unknown,
TContext = unknown,
> {
isSuccess: (
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext,
CreateStatusBasedMutationResult<
'success',
isSuccess: SignalFunction<
(
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext
TContext,
CreateStatusBasedMutationResult<
'success',
TData,
TError,
TVariables,
TContext
>
>
>
isError: (
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext,
CreateStatusBasedMutationResult<
'error',
isError: SignalFunction<
(
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext
TContext,
CreateStatusBasedMutationResult<
'error',
TData,
TError,
TVariables,
TContext
>
>
>
isPending: (
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext,
CreateStatusBasedMutationResult<
'pending',
isPending: SignalFunction<
(
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext
TContext,
CreateStatusBasedMutationResult<
'pending',
TData,
TError,
TVariables,
TContext
>
>
>
isIdle: (
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext,
CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>
isIdle: SignalFunction<
(
this: CreateMutationResult<TData, TError, TVariables, TContext>,
) => this is CreateMutationResult<
TData,
TError,
TVariables,
TContext,
CreateStatusBasedMutationResult<
'idle',
TData,
TError,
TVariables,
TContext
>
>
>
}

Expand Down

0 comments on commit eee80af

Please sign in to comment.