Skip to content

Commit 2083d02

Browse files
committed
Add TS 4.7 example snippet
1 parent f459a79 commit 2083d02

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

packages/rtk-codemods/transforms/createReducerBuilder/__testfixtures__/basic-ts.input.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export interface Todo {
66
title: string
77
}
88

9+
// This only included to make sure the codemod does not
10+
// throw a runtime error when faced with TS 4.7+ syntax such as
11+
// the `satisfies` operator and instantiation expressions
12+
const someString = 'someString' satisfies string
13+
914
export const todoAdapter = createEntityAdapter<Todo>()
1015

1116
const todoInitialState = todoAdapter.getInitialState()
@@ -18,21 +23,25 @@ createReducer(todoInitialState, {
1823
[todoAdded1a]: (state: TodoSliceState, action: PayloadAction<string>) => {
1924
// stuff
2025
},
21-
[todoAdded1b]: (state: TodoSliceState, action: PayloadAction<string>) => action.payload,
22-
[todoAdded1c + 'test']: (state:TodoSliceState, action: PayloadAction<string>) => {
26+
[todoAdded1b]: (state: TodoSliceState, action: PayloadAction<string>) =>
27+
action.payload,
28+
[todoAdded1c + 'test']: (state: TodoSliceState, action: PayloadAction<string>) => {
2329
// stuff
2430
},
2531
[todoAdded1d](state: TodoSliceState, action: PayloadAction<string>) {
2632
// stuff
2733
},
28-
[todoAdded1e]: function(state: TodoSliceState, action: PayloadAction<string>) {
34+
[todoAdded1e]: function (
35+
state: TodoSliceState,
36+
action: PayloadAction<string>
37+
) {
2938
// stuff
3039
},
3140
todoAdded1f: (state: TodoSliceState, action: PayloadAction<string>) => {
3241
//stuff
3342
},
3443
[todoAdded1g]: addOne,
35-
todoAdded1h: todoAdapter.addOne,
44+
todoAdded1h: todoAdapter.addOne
3645
})
3746

3847
createReducer(todoInitialState, {
@@ -42,7 +51,10 @@ createReducer(todoInitialState, {
4251
[todoAdded2b](state: TodoSliceState, action: PayloadAction<string>) {
4352
// stuff
4453
},
45-
[todoAdded2c]: function(state: TodoSliceState, action: PayloadAction<string>) {
54+
[todoAdded2c]: function (
55+
state: TodoSliceState,
56+
action: PayloadAction<string>
57+
) {
4658
// stuff
4759
}
4860
})

packages/rtk-codemods/transforms/createReducerBuilder/__testfixtures__/basic-ts.output.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ export interface Todo {
66
title: string
77
}
88

9+
// This only included to make sure the codemod does not
10+
// throw a runtime error when faced with TS 4.7+ syntax such as
11+
// the `satisfies` operator and instantiation expressions
12+
const someString = 'someString' satisfies string
13+
914
export const todoAdapter = createEntityAdapter<Todo>()
1015

1116
const todoInitialState = todoAdapter.getInitialState()
@@ -26,7 +31,7 @@ createReducer(todoInitialState, (builder) => {
2631

2732
builder.addCase(
2833
todoAdded1c + 'test',
29-
(state:TodoSliceState, action: PayloadAction<string>) => {
34+
(state: TodoSliceState, action: PayloadAction<string>) => {
3035
// stuff
3136
}
3237
);

0 commit comments

Comments
 (0)