Window.location.reload is falsely reported as a deprecated function

I’m getting a javascript:S1874 (Deprecated APIs should not be used) alert on a call to window.location.reload for JavaScript used in the browser.

MDN notes that the standard form includes no parameter but that including a nonstandard boolean parameter can make a difference for Firefox users.

MDN gives no indication that this function is deprecated or what if anything it has been replaced with.

Why does SonarQube (Version 8.9.5 (build 50698)) flag it as deprecated?

1 Like

Hi Ben,

Sorry for the long delay.
Could you share the code sample? There is probably a problem with type resolution.

Hi Elena,
It’s pretty short, just window.location.reload(true);

Hi Ben,

So finally I found the root cause. The version of embedded TS in SQ 8.9 provides (probably mistakenly as it was removed later) types that this method is deprecated TypeScript/lib.dom.d.ts at v4.2.4 · microsoft/TypeScript · GitHub.

In latest releases version of TS is updated and this issue is not reported anymore. So unfortunately the only fix I can suggest is to update to latest SQ or just won’t fix the issue in UI.

1 Like