Skip to content

Conversation

@k-yle
Copy link
Contributor

@k-yle k-yle commented Apr 24, 2023

writing code after location.reload() is very likely a mistake, since the code will probably never run.

So this PR changes location.reload() to return never, akin to process.exit() in node

@github-actions
Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@saschanaz
Copy link
Contributor

Thanks! LGTM.

@github-actions github-actions bot merged commit b24e2d7 into microsoft:main Apr 24, 2023
@github-actions
Copy link
Contributor

Merging because @saschanaz is a code-owner of all the changes - thanks!

@k-yle k-yle deleted the reload-never branch April 24, 2023 07:32
@HolgerJeromin
Copy link
Contributor

In my test this does not change compile behavior with code after that.
But no problem with it either.

@k-yle
Copy link
Contributor Author

k-yle commented Apr 25, 2023

Hey @HolgerJeromin, it works for me, here's an example in the TS Playground which correctly errors with TS7027

@HolgerJeromin
Copy link
Contributor

Interesting. My code uses the location object on window which breaks this error also in playground:

declare interface Location {
  reload(): never;
}
window.location.reload()
console.log("...")

@turansky
Copy link

What about iframes?

const frame = window[0]
frame.location.reload() // never

console.log("Is it really unreachable?")

@aerialist7
Copy link

aerialist7 commented Apr 25, 2023

@k-yle , self.location.reload() same as window.location.reload() breaks this error

@HolgerJeromin
Copy link
Contributor

You can use the playground link above to test yourself...
iframe does not work either

@aerialist7
Copy link

aerialist7 commented Apr 25, 2023

And yes, seems that we can have executable code after iframes location reload.
So the PR looks weird

@HolgerJeromin
Copy link
Contributor

And yes, seems that we can have executable code after iframes location reload.

Which is a good thing BTW, because an iframe reload does not break code flow in runtime of the top frame.
But this could result to false negatives which are not solvable by the developer (without many @ts-ignoreerror).

@saschanaz
Copy link
Contributor

Oh yes, I did not think about the iframe case, I guess I'll have to revert this.

saschanaz added a commit to saschanaz/types-web that referenced this pull request Apr 25, 2023
@saschanaz
Copy link
Contributor

Reverting this in #1545 to prevent unexpected breakage. Feel free to file an issue to continue the discussion.

github-actions bot pushed a commit that referenced this pull request Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants