Skip to content

Commit d99d955

Browse files
committed
fix more examples
1 parent c137349 commit d99d955

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

docs/api/createAsyncThunk.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ const fetchUserById = createAsyncThunk(
3939
)
4040

4141
interface UsersState {
42-
entities: []
42+
entities: User[]
4343
loading: 'idle' | 'pending' | 'succeeded' | 'failed'
4444
}
4545

4646
const initialState = {
4747
entities: [],
4848
loading: 'idle',
49-
} as UsersState
49+
} satisfies UserState as UsersState
5050

5151
// Then, handle actions in your reducers:
5252
const usersSlice = createSlice({
@@ -699,7 +699,7 @@ interface UsersState {
699699
const initialState = {
700700
entities: {},
701701
error: null,
702-
} as UsersState
702+
} satisfies UsersState as UsersState
703703

704704
const usersSlice = createSlice({
705705
name: 'users',

docs/api/createSlice.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface CounterState {
2525
value: number
2626
}
2727

28-
const initialState = { value: 0 } as CounterState
28+
const initialState = { value: 0 } satisfies CounterState as CounterState
2929

3030
const counterSlice = createSlice({
3131
name: 'counter',
@@ -158,7 +158,7 @@ const todosSlice = createSlice({
158158
initialState: {
159159
loading: false,
160160
todos: [],
161-
} as TodoState,
161+
} satisfies TodoState as TodoState,
162162
reducers: (create) => ({
163163
deleteTodo: create.reducer<number>((state, action) => {
164164
state.todos.splice(action.payload, 1)
@@ -608,7 +608,7 @@ const decrementBy = createAction<number>('decrementBy')
608608

609609
const counter = createSlice({
610610
name: 'counter',
611-
initialState: 0 as number,
611+
initialState: 0 satisfies number as number,
612612
reducers: {
613613
increment: (state) => state + 1,
614614
decrement: (state) => state - 1,

docs/api/matching-utilities.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ interface ExampleState {
181181
const initialState = {
182182
isSpecial: false,
183183
isInteresting: false,
184-
} as ExampleState
184+
} satisfies ExampleState as ExampleState
185185

186186
export const isSpecialAndInterestingThunk = createAsyncThunk(
187187
'isSpecialAndInterestingThunk',

docs/api/otherExports.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ interface Todo {
6666
}
6767
const addTodo = createAction<Todo>('addTodo')
6868

69-
const initialState = [] as Todo[]
69+
const initialState = [] satisfies Todo[] as Todo[]
7070

7171
const todosReducer = createReducer(initialState, (builder) => {
7272
builder.addCase(addTodo, (state, action) => {

docs/usage/usage-with-typescript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ createSlice({
273273

274274
You might have noticed that it is not a good idea to pass your `SliceState` type as a generic to `createSlice`. This is due to the fact that in almost all cases, follow-up generic parameters to `createSlice` need to be inferred, and TypeScript cannot mix explicit declaration and inference of generic types within the same "generic block".
275275

276-
The standard approach is to declare an interface or type for your state, create an initial state value that uses that type, and pass the initial state value to `createSlice`. You can also use the construct `initialState: myInitialState as SliceState`.
276+
The standard approach is to declare an interface or type for your state, create an initial state value that uses that type, and pass the initial state value to `createSlice`. You can also use the construct `initialState: myInitialState satisfies SliceState as SliceState`.
277277

278278
```ts {1,4,8,15}
279279
type SliceState = { state: 'loading' } | { state: 'finished'; data: string }
@@ -290,7 +290,7 @@ createSlice({
290290
// Or, cast the initial state as necessary
291291
createSlice({
292292
name: 'test2',
293-
initialState: { state: 'loading' } as SliceState,
293+
initialState: { state: 'loading' } satisfies SliceState as SliceState,
294294
reducers: {},
295295
})
296296
```
@@ -368,14 +368,14 @@ const fetchUserById = createAsyncThunk(
368368
)
369369

370370
interface UsersState {
371-
entities: []
371+
entities: User[]
372372
loading: 'idle' | 'pending' | 'succeeded' | 'failed'
373373
}
374374

375375
const initialState = {
376376
entities: [],
377377
loading: 'idle',
378-
} as UsersState
378+
} satisfies UsersState as UsersState
379379

380380
const usersSlice = createSlice({
381381
name: 'users',

docs/virtual/matchers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface ExampleState {
3737
export const initialState = {
3838
isSpecial: false,
3939
isInteresting: false,
40-
} as ExampleState
40+
} satisfies ExampleState as ExampleState
4141

4242
export const isSpecialAndInterestingThunk = createAsyncThunk(
4343
'isSpecialAndInterestingThunk',

0 commit comments

Comments
 (0)