From 081cba04a2cb5359ab30f8d3c86fc54cd92bca60 Mon Sep 17 00:00:00 2001 From: David-Emmanuel DIVERNOIS Date: Tue, 20 Aug 2024 11:58:10 +0200 Subject: [PATCH 1/2] fix(angular-query): fix type of isSuccess, isError, isPending, isIdle --- .../etc/angular-query-experimental.api.md | 9 +++++---- .../src/__tests__/test-utils.ts | 4 ++-- .../angular-query-experimental/src/types.ts | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 14 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 aae6ed1093..484568869c 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..cb3de36bd7 100644 --- a/packages/angular-query-experimental/src/__tests__/test-utils.ts +++ b/packages/angular-query-experimental/src/__tests__/test-utils.ts @@ -1,4 +1,4 @@ -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 +86,7 @@ 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..dbdaad707f 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,7 +233,7 @@ export interface BaseMutationNarrowing< TVariables = unknown, TContext = unknown, > { - isSuccess: ( + isSuccess: SignalFunction<( this: CreateMutationResult, ) => this is CreateMutationResult< TData, @@ -244,8 +247,8 @@ export interface BaseMutationNarrowing< TVariables, TContext > - > - isError: ( + >> + isError: SignalFunction<( this: CreateMutationResult, ) => this is CreateMutationResult< TData, @@ -259,8 +262,8 @@ export interface BaseMutationNarrowing< TVariables, TContext > - > - isPending: ( + >> + isPending: SignalFunction<( this: CreateMutationResult, ) => this is CreateMutationResult< TData, @@ -274,8 +277,8 @@ export interface BaseMutationNarrowing< TVariables, TContext > - > - isIdle: ( + >> + isIdle: SignalFunction<( this: CreateMutationResult, ) => this is CreateMutationResult< TData, @@ -283,7 +286,7 @@ export interface BaseMutationNarrowing< TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext> - > + >> } /** From 62dc7a876d707057b25dd245dd93c64c6bbe8bca Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 21 Aug 2024 23:48:06 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- .../src/__tests__/test-utils.ts | 11 +- .../angular-query-experimental/src/types.ts | 100 ++++++++++-------- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/packages/angular-query-experimental/src/__tests__/test-utils.ts b/packages/angular-query-experimental/src/__tests__/test-utils.ts index cb3de36bd7..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, type Signal, 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]: T[K] extends Signal ? ReturnType : never }>, + 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 dbdaad707f..8118fa4feb 100644 --- a/packages/angular-query-experimental/src/types.ts +++ b/packages/angular-query-experimental/src/types.ts @@ -222,7 +222,7 @@ type CreateStatusBasedMutationResult< { status: TStatus } > -type SignalFunction any> = T & Signal>; +type SignalFunction any> = T & Signal> /** * @public @@ -233,60 +233,74 @@ export interface BaseMutationNarrowing< TVariables = unknown, TContext = unknown, > { - isSuccess: SignalFunction<( - 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: SignalFunction<( - 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: SignalFunction<( - 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: SignalFunction<( - 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 + > + > + > } /**