gaearon / gaearon/react-hot-loader

Explain in Troubleshooting.md why "const anyModule = module as any;" doesn't work as expected

Open
#1,560 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.2k
Forks
775
PR merge metrics
No merged PRs in 30d

Description

At https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md, you say that

```
const anyModule = module as any;
if (anyModule.hot) {
anyModule.hot.accept('./app', () => render(App));
}
```

will lead to full page reloads, but

```
if ((module as any).hot) {
(module as any).hot.accept('./app', () => render(App));
}
```

will work. I am pretty confused by that, as I'd expect both to lead to the same result. Not understanding it makes it harder to remember too.

Could you maybe add to the document why it is behaving like this?

(Or if you don't have the time to do that at the moment, give me a hint here?)

Contributor guide

Open the contributing guide

Research direction

Open docs/Troubleshooting.md and read the section containing the two module.hot examples. Compare the behavior described for the assigned variable and the inline type assertion, then document why they differ. Done means the troubleshooting guidance explains the distinction clearly enough that readers can understand and remember it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.