File tree Expand file tree Collapse file tree 5 files changed +26
-1
lines changed Expand file tree Collapse file tree 5 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ export interface ActionCreatorWithoutPayload<T extends string = string>
144
144
* Calling this {@link redux#ActionCreator} will
145
145
* return a {@link PayloadAction} of type `T` with a payload of `undefined`
146
146
*/
147
- ( ) : PayloadAction < undefined , T >
147
+ ( noArgument : void ) : PayloadAction < undefined , T >
148
148
}
149
149
150
150
/**
Original file line number Diff line number Diff line change @@ -412,6 +412,7 @@ export interface ApiEndpointQuery<
412
412
// eslint-disable-next-line @typescript-eslint/no-unused-vars
413
413
Definitions extends EndpointDefinitions
414
414
> {
415
+ name : string
415
416
/**
416
417
* All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
417
418
*/
@@ -425,6 +426,7 @@ export interface ApiEndpointMutation<
425
426
// eslint-disable-next-line @typescript-eslint/no-unused-vars
426
427
Definitions extends EndpointDefinitions
427
428
> {
429
+ name : string
428
430
/**
429
431
* All of these are `undefined` at runtime, purely to be used in TypeScript declarations!
430
432
*/
@@ -603,6 +605,7 @@ export const coreModule = (): Module<CoreModule> => ({
603
605
safeAssign (
604
606
anyApi . endpoints [ endpointName ] ,
605
607
{
608
+ name : endpointName ,
606
609
select : buildQuerySelector ( endpointName , definition ) ,
607
610
initiate : buildInitiateQuery ( endpointName , definition ) ,
608
611
} ,
@@ -612,6 +615,7 @@ export const coreModule = (): Module<CoreModule> => ({
612
615
safeAssign (
613
616
anyApi . endpoints [ endpointName ] ,
614
617
{
618
+ name : endpointName ,
615
619
select : buildMutationSelector ( ) ,
616
620
initiate : buildInitiateMutation ( endpointName ) ,
617
621
} ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export type {
10
10
EndpointDefinition ,
11
11
QueryDefinition ,
12
12
MutationDefinition ,
13
+ TagDescription ,
13
14
} from './endpointDefinitions'
14
15
export { fetchBaseQuery } from './fetchBaseQuery'
15
16
export type {
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
import { server } from './mocks/server'
19
19
import { rest } from 'msw'
20
20
import { SerializeQueryArgs } from '../defaultSerializeQueryArgs'
21
+ import { string } from 'yargs'
21
22
22
23
const originalEnv = process . env . NODE_ENV
23
24
beforeAll ( ( ) => void ( ( process . env as any ) . NODE_ENV = 'development' ) )
@@ -43,6 +44,9 @@ test('sensible defaults', () => {
43
44
return { url : `user/${ id } ` }
44
45
} ,
45
46
} ) ,
47
+ updateUser : build . mutation < unknown , void > ( {
48
+ query : ( ) => '' ,
49
+ } ) ,
46
50
} ) ,
47
51
} )
48
52
configureStore ( {
@@ -60,6 +64,9 @@ test('sensible defaults', () => {
60
64
expectType < TagTypes > ( ANY as never )
61
65
// @ts -expect-error
62
66
expectType < TagTypes > ( 0 )
67
+
68
+ expect ( api . endpoints . getUser . name ) . toBe ( 'getUser' )
69
+ expect ( api . endpoints . updateUser . name ) . toBe ( 'updateUser' )
63
70
} )
64
71
65
72
describe ( 'wrong tagTypes log errors' , ( ) => {
Original file line number Diff line number Diff line change
1
+ import React from 'react'
1
2
import type { Action , AnyAction , ActionCreator } from 'redux'
2
3
import type {
3
4
PayloadAction ,
@@ -344,3 +345,15 @@ import { expectType } from './helpers'
344
345
type AnyPayload = ReturnType < typeof anyCreator > [ 'payload' ]
345
346
expectType < IsAny < AnyPayload , true , false > > ( true )
346
347
}
348
+
349
+ // Verify action creators should not be passed directly as arguments
350
+ // to React event handlers if there shouldn't be a payload
351
+ {
352
+ const emptyAction = createAction < void > ( 'empty/action' )
353
+ function TestComponent ( ) {
354
+ // This typically leads to an error like:
355
+ // // A non-serializable value was detected in an action, in the path: `payload`.
356
+ // @ts -expect-error Should error because `void` and `MouseEvent` aren't compatible
357
+ return < button onClick = { emptyAction } > +</ button >
358
+ }
359
+ }
You can’t perform that action at this time.
0 commit comments