-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning never
from redirect
function makes incorrect behavior
#436
Comments
The important part is this can't impact the return type of the function that returns it. It is intended that redirect is always thrown or returned as it doesn't do the redirect but returns the redirect. So in a sense the code that is incorrect here would never work anyway. The fact is |
Yes it is more like, Although, I'm just a starter and don't know all the cases yet to use the redirect function, maybe |
When combined with
I can imagine an alternative that uses branded
When a |
If a function returns something, it must be explicitly documented. I understand that I have to return the truthy value from the In this case let res;
if (condition1) {
res = redirect('page1');
someOperation();
}
else if (condition2) {
res = redirect('page2');
someAnotherOperation();
}
else {
res = redirect('page3');
}
return res;
} I know this is not a good, clean code and can be optimized, but that's irrelevant. At least developer must be aware of things and shouldn't get an error that says unreachable code. Junior devs can even get far more confused. If something like So basically hidden behaviors and mental statements is just bad DX. Even if the return value is being stripped away in background, doesn't change the fact. All procedure must be and can be documented and implemented correctly, IMHO. |
imo that specific use case is questionable but there's definitely an argument that it should be valid. Here's a demo of how it could work. |
This is fixed in the next version of the router (v0.14.0). The types from helpers will reflect reality and it will be the |
Describe the bug (it's more like a DX problem)
When I use
redirect
, its return value makes TS to throw a warning and makes you wrote an incorrect code.Like, I get confused if the
redirect
function is acting likeprocess.exit(0)
. I know this is unlikely considering that it doesn't actually break the code, but still, the error is also annoying to have it thereSource
solid-router/src/data/response.ts
Line 24 in 517a28e
Your Example Website or App
The root cause is specific enough, IMO
Steps to Reproduce the Bug or Issue
Expected behavior
Not to throw error.
redirect
function should probably return the type of the object it returns. If it is an intended behavior, then at least it should returnvoid
orundefined
orunknown
Screenshots or Videos
No response
Platform
Additional context
Probably, the
reload
function may need to be evaluated as well.Also, I would have opened up a PR, but I'm not sure why there's a
never
usage and what gets affected after changing it.The text was updated successfully, but these errors were encountered: