Skip to content

Commit 2c7d5c2

Browse files
gonaumovzalmoxisus
authored andcommitted
Add an example how to avoid any without using of redux-devtools-extension npm package (#660)
1 parent 1ea8566 commit 2c7d5c2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/Recipes.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@ const store = createStore(
1414
```
1515
Note that you many need to set `no-any` to false in your `tslint.json` file.
1616

17+
Alternatively you can use typeguard in order to avoid
18+
casting to any.
19+
20+
```typescript
21+
import { createStore, StoreEnhancer } from "redux";
22+
23+
// ...
24+
25+
type WindowWithDevTools = Window & {
26+
__REDUX_DEVTOOLS_EXTENSION__: () => StoreEnhancer<unknown, {}>
27+
}
28+
29+
const isReduxDevtoolsExtenstionExist =
30+
(arg: Window | WindowWithDevTools):
31+
arg is WindowWithDevTools => {
32+
return '__REDUX_DEVTOOLS_EXTENSION__' in arg;
33+
}
34+
35+
// ...
36+
37+
const store = createStore(rootReducer, initialState,
38+
isReduxDevtoolsExtenstionExist(window) ?
39+
window.__REDUX_DEVTOOLS_EXTENSION__() : undefined)
40+
```
41+
1742
### Export from browser console or from application
1843

1944
```js

0 commit comments

Comments
 (0)