@@ -22,16 +22,19 @@ function expectType<T>(p: T): T {
22
22
* Test: PayloadAction type parameter is optional (defaults to `any`).
23
23
*/
24
24
{
25
+ // typings:expect-error
25
26
const action : PayloadAction = { type : '' , payload : 5 }
27
+ // typings:expect-error
26
28
const numberPayload : number = action . payload
29
+ // typings:expect-error
27
30
const stringPayload : string = action . payload
28
31
}
29
32
30
33
/*
31
34
* Test: PayloadAction has a string type tag.
32
35
*/
33
36
{
34
- const action : PayloadAction = { type : '' , payload : 5 }
37
+ const action : PayloadAction < number > = { type : '' , payload : 5 }
35
38
36
39
// typings:expect-error
37
40
const action2 : PayloadAction = { type : 1 , payload : 5 }
@@ -41,7 +44,7 @@ function expectType<T>(p: T): T {
41
44
* Test: PayloadAction is compatible with Action<string>
42
45
*/
43
46
{
44
- const action : PayloadAction = { type : '' , payload : 5 }
47
+ const action : PayloadAction < number > = { type : '' , payload : 5 }
45
48
const stringAction : Action < string > = action
46
49
}
47
50
@@ -58,10 +61,12 @@ function expectType<T>(p: T): T {
58
61
payload
59
62
} ) ,
60
63
{ type : 'action' }
61
- ) as PayloadActionCreator
64
+ ) as PayloadActionCreator < number >
62
65
63
66
expectType < PayloadAction < number > > ( actionCreator ( 1 ) )
67
+ // typings:expect-error
64
68
expectType < PayloadAction < undefined > > ( actionCreator ( ) )
69
+ // typings:expect-error
65
70
expectType < PayloadAction < undefined > > ( actionCreator ( undefined ) )
66
71
67
72
// typings:expect-error
@@ -110,22 +115,21 @@ function expectType<T>(p: T): T {
110
115
}
111
116
112
117
/*
113
- * Test: createAction() type parameter is optional (defaults to `any `).
118
+ * Test: createAction() type parameter is required, not inferred (defaults to `void `).
114
119
*/
115
120
{
116
- const increment = createAction ( 'increment' )
121
+ const increment = createAction < number > ( 'increment' )
117
122
const n : number = increment ( 1 ) . payload
123
+ // typings:expect-error
118
124
const s : string = increment ( '1' ) . payload
119
-
120
- // but infers the payload type to be the argument type
121
125
// typings:expect-error
122
126
const t : string = increment ( 1 ) . payload
123
127
}
124
128
/*
125
129
* Test: createAction().type is a string literal.
126
130
*/
127
131
{
128
- const increment = createAction ( 'increment' )
132
+ const increment = createAction < number , 'increment' > ( 'increment' )
129
133
const n : string = increment ( 1 ) . type
130
134
const s : 'increment' = increment ( 1 ) . type
131
135
0 commit comments