Skip to content

Commit baa947d

Browse files
committed
Fixed tsconfig and 34 solution
1 parent 653b655 commit baa947d

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

scripts/tests/__snapshots__/all.test.ts.snap

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ src/07-challenges/34-dynamic-reducer.problem.ts(86,23): error TS2344: Type 'fals
117117
src/07-challenges/34-dynamic-reducer.problem.ts(95,7): error TS2578: Unused '@ts-expect-error' directive.
118118
src/07-challenges/34-dynamic-reducer.problem.ts(104,5): error TS2578: Unused '@ts-expect-error' directive.
119119
src/07-challenges/38-challenge-custom-jsx-element.problem.tsx(13,17): error TS2339: Property 'custom-element' does not exist on type 'JSX.IntrinsicElements'.
120-
src/07-challenges/38-challenge-custom-jsx-element.problem.tsx(13,17): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
121120
src/07-challenges/38-challenge-custom-jsx-element.problem.tsx(13,44): error TS2339: Property 'custom-element' does not exist on type 'JSX.IntrinsicElements'.
122-
src/07-challenges/38-challenge-custom-jsx-element.solution.tsx(18,17): error TS17004: Cannot use JSX unless the '--jsx' flag is provided.
123121
,"
124122
`;
125123
@@ -1554,15 +1552,9 @@ exports[`vitest > Should have the correct Vitest errors 1`] = `
15541552
"ancestorTitles": [
15551553
"",
15561554
],
1557-
"failureMessages": [
1558-
"expected { username: 'awdawdawd', password: '' } to deeply equal { username: 'foo', password: 'bar' }",
1559-
],
1555+
"failureMessages": [],
15601556
"fullName": " Should return the new state after LOG_IN",
1561-
"location": {
1562-
"column": 17,
1563-
"line": 78,
1564-
},
1565-
"status": "failed",
1557+
"status": "passed",
15661558
"title": "Should return the new state after LOG_IN",
15671559
},
15681560
{
@@ -1595,7 +1587,7 @@ exports[`vitest > Should have the correct Vitest errors 1`] = `
15951587
],
15961588
"message": "",
15971589
"name": "src/07-challenges/34-dynamic-reducer.solution.ts",
1598-
"status": "failed",
1590+
"status": "passed",
15991591
},
16001592
],
16011593
}

src/07-challenges/34-dynamic-reducer.solution.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type PayloadsToDiscriminatedUnion<T extends Record<string, any>> = {
77

88
export class DynamicReducer<
99
TState,
10-
TPayloadMap extends Record<string, any> = {}
10+
TPayloadMap extends Record<string, any> = {},
1111
> {
1212
private handlers = {} as Record<
1313
string,
@@ -16,7 +16,7 @@ export class DynamicReducer<
1616

1717
addHandler<TType extends string, TPayload extends object>(
1818
type: TType,
19-
handler: (state: TState, payload: TPayload) => TState
19+
handler: (state: TState, payload: TPayload) => TState,
2020
): DynamicReducer<TState, TPayloadMap & Record<TType, TPayload>> {
2121
this.handlers[type] = handler;
2222

@@ -25,7 +25,7 @@ export class DynamicReducer<
2525

2626
reduce(
2727
state: TState,
28-
action: PayloadsToDiscriminatedUnion<TPayloadMap>
28+
action: PayloadsToDiscriminatedUnion<TPayloadMap>,
2929
): TState {
3030
const handler = this.handlers[action.type];
3131
if (!handler) {
@@ -49,7 +49,7 @@ const reducer = new DynamicReducer<State>()
4949
username: action.username,
5050
password: action.password,
5151
};
52-
}
52+
},
5353
)
5454
.addHandler("LOG_OUT", () => {
5555
return {
@@ -69,19 +69,19 @@ it("Should return the new state after LOG_IN", () => {
6969
{ username: "", password: "" },
7070
{
7171
type: "UPDATE_USERNAME",
72-
username: "awdawdawd",
73-
}
72+
username: "new-password",
73+
},
7474
);
7575

7676
type test = [Expect<Equal<typeof state, State>>];
7777

78-
expect(state).toEqual({ username: "foo", password: "bar" });
78+
expect(state).toEqual({ username: "new-password", password: "" });
7979
});
8080

8181
it("Should return the new state after LOG_OUT", () => {
8282
const state = reducer.reduce(
8383
{ username: "foo", password: "bar" },
84-
{ type: "LOG_OUT" }
84+
{ type: "LOG_OUT" },
8585
);
8686

8787
type test = [Expect<Equal<typeof state, State>>];
@@ -95,7 +95,7 @@ it("Should error if you pass it an incorrect action", () => {
9595
{
9696
// @ts-expect-error
9797
type: "NOT_ALLOWED",
98-
}
98+
},
9999
);
100100
});
101101

@@ -105,6 +105,6 @@ it("Should error if you pass an incorrect payload", () => {
105105
// @ts-expect-error
106106
{
107107
type: "LOG_IN",
108-
}
108+
},
109109
);
110110
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"module": "ES2022",
88
"moduleResolution": "node",
99
"noEmit": true,
10+
"jsx": "preserve",
1011
"isolatedModules": true,
1112
"esModuleInterop": true,
1213
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)