Skip to content

Commit 2a12ccc

Browse files
committed
Test that create keys are not typed to be optional
1 parent 5982b1e commit 2a12ccc

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

docs/old/typescript/actions.dts-jest.ts

+28
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@ import riduce from "../../../src"
2929
actions.nested.string
3030
}
3131

32+
// @dts-jest:group Action keys are not possibly undefined but is sensitive to passing undefined
33+
{
34+
interface State {
35+
num: number;
36+
nested?: {
37+
deep?: boolean;
38+
};
39+
}
40+
41+
const initialState: State = {
42+
num: 4,
43+
nested: {
44+
deep: true,
45+
},
46+
};
47+
48+
const [reducer, actions] = riduce(initialState);
49+
50+
// @dts-jest:pass
51+
actions.nested.deep;
52+
53+
// @dts-jest:pass
54+
actions.nested.deep.create.update(undefined);
55+
56+
// @dts-jest:fail
57+
actions.num.create.update(undefined);
58+
}
59+
3260
// @dts-jest:group Creator update is sensitive to the leaf type
3361
{
3462
const initialState = {

src/proxy/createActionsProxy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type ActionsProxy<
88
> = {
99
create: CreateAPI<LeafT, TreeT, RiducerDictT>;
1010
} & {
11-
[K in keyof LeafT]: ActionsProxy<LeafT[K], TreeT, RiducerDictT>;
11+
[K in keyof Required<LeafT>]: ActionsProxy<LeafT[K], TreeT, RiducerDictT>;
1212
};
1313

1414
function createActionsProxy<

src/riduce.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import leafReducer from "./leafReducer";
22
import { createActionsProxy } from "./proxy";
33
import { ActionsProxy } from "./proxy/createActionsProxy";
44
import {
5-
Action,
65
RiducerDict,
76
isBundledAction,
8-
CallbackAction,
97
isCallbackAction,
108
RiduceAction,
119
OrdinaryAction,

0 commit comments

Comments
 (0)