Skip to content

Commit e1a4222

Browse files
committed
Copied over reselect known limitations
1 parent bf4d621 commit e1a4222

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/api/createSelector.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,39 @@ const createTypedDraftSafeSelector = createDraftSafeSelector.withTypes<RootState
9999

100100
Import and use the pre-typed `createTypedDraftSafeSelector` function, and it will automatically know that the `state` argument is of type `RootState`.
101101

102+
:::warning
103+
Currently this approach only works if input selectors are provided as a single array.
104+
105+
If you pass the input selectors as separate inline arguments, the parameter types of the result function will not be inferred. As a workaround you can either
106+
107+
1. Wrap your input selectors in a single array
108+
2. You can annotate the parameter types of the result function:
109+
110+
```ts no-transpile
111+
import { createSelector } from 'reselect'
112+
113+
interface Todo {
114+
id: number
115+
completed: boolean
116+
}
117+
118+
interface Alert {
119+
id: number
120+
read: boolean
121+
}
122+
123+
export interface RootState {
124+
todos: Todo[]
125+
alerts: Alert[]
126+
}
127+
128+
export const createTypedDraftSafeSelector = createDraftSafeSelector.withTypes<RootState>()
129+
130+
const selectTodoIds = createTypedDraftSafeSelector(
131+
// Type of `state` is set to `RootState`, no need to manually set the type
132+
state => state.todos,
133+
// ❌ Known limitation: Parameter types are not inferred in this scenario
134+
// so you will have to manually annotate them.
135+
(todos: Todo[]) => todos.map(({ id }) => id)
136+
)
137+
```

0 commit comments

Comments
 (0)