Skip to content

Commit 74e7cb4

Browse files
committed
Add checks for extra in `withTypes
1 parent b27f404 commit 74e7cb4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

packages/toolkit/src/tests/createAsyncThunk.typetest.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ const anyAction = { type: 'foo' } as AnyAction
603603
state: RootState
604604
dispatch: AppDispatch
605605
rejectValue: string
606+
extra: { s: string; n: number }
606607
}>()
607608

608609
// inferred usage
@@ -618,6 +619,11 @@ const anyAction = { type: 'foo' } as AnyAction
618619
return getState().foo.value
619620
})
620621

622+
// correct extra type
623+
const { s, n } = api.extra
624+
expectExactType<string>(s)
625+
expectExactType<number>(n)
626+
621627
if (1 < 2)
622628
// @ts-expect-error
623629
return api.rejectWithValue(5)
@@ -638,6 +644,11 @@ const anyAction = { type: 'foo' } as AnyAction
638644
expectExactType<() => { foo: { value: number } }>(ANY)(getState)
639645
return getState().foo.value
640646
})
647+
// correct extra type
648+
const { s, n } = api.extra
649+
expectExactType<string>(s)
650+
expectExactType<number>(n)
651+
641652
if (1 < 2)
642653
// @ts-expect-error
643654
return api.rejectWithValue(5)
@@ -660,6 +671,10 @@ const anyAction = { type: 'foo' } as AnyAction
660671
expectExactType<() => { foo: { value: number } }>(ANY)(getState)
661672
return getState().foo.value
662673
})
674+
// correct extra type
675+
const { s, n } = api.extra
676+
expectExactType<string>(s)
677+
expectExactType<number>(n)
663678
if (1 < 2) return api.rejectWithValue(5)
664679
if (1 < 2)
665680
// @ts-expect-error

0 commit comments

Comments
 (0)