Skip to content

Commit

Permalink
Add an example how to avoid any without using of redux-devtools-exten…
Browse files Browse the repository at this point in the history
…sion npm package
  • Loading branch information
gonaumov committed Jun 10, 2019
1 parent b3fed33 commit 1960853
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/Recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ const store = createStore(
```
Note that you many need to set `no-any` to false in your `tslint.json` file.

Alternatively you can use typeguard in order to avoid
casting to any.

```typescript
import { createStore, StoreEnhancer } from "redux";

// ...

type WindowWithDevTools = Window & {
__REDUX_DEVTOOLS_EXTENSION__: () => StoreEnhancer<unknown, {}>
}

const isReduzDevtoolsExtenstionExist =
(arg: Window | WindowWithDevTools):
arg is WindowWithDevTools => {
return '__REDUX_DEVTOOLS_EXTENSION__' in arg;
}

// ...

const store = createStore(runes, initialState,
isReduzDevtoolsExtenstionExist(window) ?
window.__REDUX_DEVTOOLS_EXTENSION__() : undefined)
```

### Export from browser console or from application

```js
Expand Down

0 comments on commit 1960853

Please sign in to comment.