From 8ffdc15cec0248805f10ecae6b6194ba43212d92 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Fri, 16 Jun 2023 00:33:59 +0200 Subject: [PATCH] Fix mutation types order (#2669) --- mutation/src/types.ts | 6 +++--- test/type/{mutator.ts => mutate.ts} | 0 test/type/mutation.ts | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) rename test/type/{mutator.ts => mutate.ts} (100%) create mode 100644 test/type/mutation.ts diff --git a/mutation/src/types.ts b/mutation/src/types.ts index c573b5747..c0d02a044 100644 --- a/mutation/src/types.ts +++ b/mutation/src/types.ts @@ -49,7 +49,7 @@ export type SWRMutationConfiguration< } type RemoveUndefined = T extends undefined ? never : T -interface TriggerWithArgs< +export interface TriggerWithArgs< Data = any, Error = any, SWRMutationKey extends Key = Key, @@ -87,7 +87,7 @@ interface TriggerWithArgs< ): Promise } -interface TriggerWithoutArgs< +export interface TriggerWithoutArgs< Data = any, Error = any, SWRMutationKey extends Key = Key, @@ -140,7 +140,7 @@ export interface SWRMutationResponse< * the fetcher, and override the options for the mutation hook. */ trigger: [ExtraArg] extends [never] - ? TriggerWithoutArgs + ? TriggerWithoutArgs : TriggerWithArgs /** * Function to reset the mutation state (`data`, `error`, and `isMutating`). diff --git a/test/type/mutator.ts b/test/type/mutate.ts similarity index 100% rename from test/type/mutator.ts rename to test/type/mutate.ts diff --git a/test/type/mutation.ts b/test/type/mutation.ts new file mode 100644 index 000000000..59590efe4 --- /dev/null +++ b/test/type/mutation.ts @@ -0,0 +1,8 @@ +import useSWRMutation from 'swr/mutation' +import { expectType } from './utils' +import type { TriggerWithoutArgs } from '../../mutation/src/types' + +export function useConfigMutation() { + const { trigger } = useSWRMutation('key', k => k) + expectType>(trigger) +}