Skip to content

Commit e454251

Browse files
authored
docs: add satisfies keyword with type assertion (#3623)
1 parent 2b549dd commit e454251

File tree

6 files changed

+7
-11
lines changed

6 files changed

+7
-11
lines changed

docs/api/autoBatchEnhancer.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface CounterState {
2727

2828
const counterSlice = createSlice({
2929
name: 'counter',
30-
initialState: { value: 0 } as CounterState,
30+
initialState: { value: 0 } satisfies CounterState as CounterState,
3131
reducers: {
3232
incrementBatched: {
3333
// Batched, low-priority

docs/api/createReducer.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const increment = createAction('counter/increment')
5454
const decrement = createAction('counter/decrement')
5555
const incrementByAmount = createAction<number>('counter/incrementByAmount')
5656

57-
const initialState = { value: 0 } as CounterState
57+
const initialState = { value: 0 } satisfies CounterState as CounterState
5858

5959
const counterReducer = createReducer(initialState, (builder) => {
6060
builder

docs/api/createSlice.mdx

+1-1
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',

docs/tutorials/quick-start.mdx

+1-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ export interface CounterState {
117117
value: number
118118
}
119119

120-
const initialState: CounterState = {
121-
value: 0,
122-
}
120+
const initialState = { value: 0 } satisfies CounterState as CounterState
123121

124122
export const counterSlice = createSlice({
125123
name: 'counter',

docs/tutorials/typescript.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ interface CounterState {
108108
}
109109

110110
// Define the initial state using that type
111-
const initialState: CounterState = {
112-
value: 0,
113-
}
111+
const initialState = { value: 0 } satisfies CounterState as CounterState
114112
// highlight-end
115113

116114
export const counterSlice = createSlice({
@@ -149,7 +147,7 @@ In some cases, [TypeScript may unnecessarily tighten the type of the initial sta
149147
// Workaround: cast state instead of declaring variable type
150148
const initialState = {
151149
value: 0,
152-
} as CounterState
150+
} satisfies CounterState as CounterState
153151
```
154152

155153
### Use Typed Hooks in Components

docs/usage/usage-with-typescript.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ createSlice({
326326
// Or, cast the initial state as necessary
327327
createSlice({
328328
name: 'test2',
329-
initialState: { state: 'loading' } as SliceState,
329+
initialState: { state: 'loading' } satisfies SliceState as SliceState,
330330
reducers: {},
331331
})
332332
```

0 commit comments

Comments
 (0)