From eee80aff36cd52e6a5eaf12ef7760cb0025bab69 Mon Sep 17 00:00:00 2001 From: divdavem Date: Fri, 30 Aug 2024 01:00:28 +0200 Subject: [PATCH] fix(angular-query): fix type of isSuccess, isError, isPending, isIdle 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> --- .../etc/angular-query-experimental.api.md | 9 +- .../src/__tests__/test-utils.ts | 11 ++- .../angular-query-experimental/src/types.ts | 93 +++++++++++-------- 3 files changed, 69 insertions(+), 44 deletions(-) diff --git a/packages/angular-query-experimental/etc/angular-query-experimental.api.md b/packages/angular-query-experimental/etc/angular-query-experimental.api.md index c2abbe0674..b58ce9d1da 100644 --- a/packages/angular-query-experimental/etc/angular-query-experimental.api.md +++ b/packages/angular-query-experimental/etc/angular-query-experimental.api.md @@ -36,15 +36,16 @@ import type { ThrowOnError } from '@tanstack/query-core'; // @public (undocumented) export interface BaseMutationNarrowing { // (undocumented) - isError: (this: CreateMutationResult) => this is CreateMutationResult>; + isError: SignalFunction<(this: CreateMutationResult) => this is CreateMutationResult>>; // (undocumented) - isIdle: (this: CreateMutationResult) => this is CreateMutationResult>; + isIdle: SignalFunction<(this: CreateMutationResult) => this is CreateMutationResult>>; // (undocumented) - isPending: (this: CreateMutationResult) => this is CreateMutationResult>; + isPending: SignalFunction<(this: CreateMutationResult) => this is CreateMutationResult>>; + // 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) => this is CreateMutationResult>; + isSuccess: SignalFunction<(this: CreateMutationResult) => this is CreateMutationResult>>; } // @public (undocumented) diff --git a/packages/angular-query-experimental/src/__tests__/test-utils.ts b/packages/angular-query-experimental/src/__tests__/test-utils.ts index 8c075049c4..3a465f8eb4 100644 --- a/packages/angular-query-experimental/src/__tests__/test-utils.ts +++ b/packages/angular-query-experimental/src/__tests__/test-utils.ts @@ -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' @@ -86,7 +91,9 @@ function evaluateSignals>( export const expectSignals = >( obj: T, - expected: Partial<{ [K in keyof T]: ReturnType }>, + expected: Partial<{ + [K in keyof T]: T[K] extends Signal ? ReturnType : never + }>, ): void => { expect(evaluateSignals(obj)).toMatchObject(expected) } diff --git a/packages/angular-query-experimental/src/types.ts b/packages/angular-query-experimental/src/types.ts index a1b24c06c9..8118fa4feb 100644 --- a/packages/angular-query-experimental/src/types.ts +++ b/packages/angular-query-experimental/src/types.ts @@ -14,6 +14,7 @@ import type { QueryObserverOptions, QueryObserverResult, } from '@tanstack/query-core' +import type { Signal } from '@angular/core' import type { MapToSignals } from './signal-proxy' /** @@ -221,6 +222,8 @@ type CreateStatusBasedMutationResult< { status: TStatus } > +type SignalFunction any> = T & Signal> + /** * @public */ @@ -230,59 +233,73 @@ export interface BaseMutationNarrowing< TVariables = unknown, TContext = unknown, > { - isSuccess: ( - this: CreateMutationResult, - ) => this is CreateMutationResult< - TData, - TError, - TVariables, - TContext, - CreateStatusBasedMutationResult< - 'success', + isSuccess: SignalFunction< + ( + this: CreateMutationResult, + ) => this is CreateMutationResult< TData, TError, TVariables, - TContext + TContext, + CreateStatusBasedMutationResult< + 'success', + TData, + TError, + TVariables, + TContext + > > > - isError: ( - this: CreateMutationResult, - ) => this is CreateMutationResult< - TData, - TError, - TVariables, - TContext, - CreateStatusBasedMutationResult< - 'error', + isError: SignalFunction< + ( + this: CreateMutationResult, + ) => this is CreateMutationResult< TData, TError, TVariables, - TContext + TContext, + CreateStatusBasedMutationResult< + 'error', + TData, + TError, + TVariables, + TContext + > > > - isPending: ( - this: CreateMutationResult, - ) => this is CreateMutationResult< - TData, - TError, - TVariables, - TContext, - CreateStatusBasedMutationResult< - 'pending', + isPending: SignalFunction< + ( + this: CreateMutationResult, + ) => this is CreateMutationResult< TData, TError, TVariables, - TContext + TContext, + CreateStatusBasedMutationResult< + 'pending', + TData, + TError, + TVariables, + TContext + > > > - isIdle: ( - this: CreateMutationResult, - ) => this is CreateMutationResult< - TData, - TError, - TVariables, - TContext, - CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext> + isIdle: SignalFunction< + ( + this: CreateMutationResult, + ) => this is CreateMutationResult< + TData, + TError, + TVariables, + TContext, + CreateStatusBasedMutationResult< + 'idle', + TData, + TError, + TVariables, + TContext + > + > > }