Skip to content

Commit

Permalink
Fix mutation types order (#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jun 15, 2023
1 parent c263f06 commit 8ffdc15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mutation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type SWRMutationConfiguration<
}

type RemoveUndefined<T> = T extends undefined ? never : T
interface TriggerWithArgs<
export interface TriggerWithArgs<
Data = any,
Error = any,
SWRMutationKey extends Key = Key,
Expand Down Expand Up @@ -87,7 +87,7 @@ interface TriggerWithArgs<
): Promise<Data | undefined>
}

interface TriggerWithoutArgs<
export interface TriggerWithoutArgs<
Data = any,
Error = any,
SWRMutationKey extends Key = Key,
Expand Down Expand Up @@ -140,7 +140,7 @@ export interface SWRMutationResponse<
* the fetcher, and override the options for the mutation hook.
*/
trigger: [ExtraArg] extends [never]
? TriggerWithoutArgs<Data, Error, ExtraArg, SWRMutationKey>
? TriggerWithoutArgs<Data, Error, SWRMutationKey, ExtraArg>
: TriggerWithArgs<Data, Error, SWRMutationKey, ExtraArg>
/**
* Function to reset the mutation state (`data`, `error`, and `isMutating`).
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions test/type/mutation.ts
Original file line number Diff line number Diff line change
@@ -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<TriggerWithoutArgs<'key', any, string, never>>(trigger)
}

0 comments on commit 8ffdc15

Please sign in to comment.