The redirect
function allows to avoid a parameter for the Location
#15594
Labels
good first issue
Easy to fix issues, good for newcomers
Milestone
Bug report
Describe the bug
The
redirect
function added in #14705 allows to set a status code or URL as second argument, and an optional third argument for the URL if the second argument was used for the status code.However, the function signature allows setting a status code without providing a URL. In those cases the
Location
header would be set toundefined
, which throws an error.To Reproduce
pages/api/index.ts
with this content:next dev
and executecurl localhost:300/api
Expected behavior
TypeScript should have caught the error upfront.
Personally I think it'd make more sense to have a signature like this:
so that no matter what, the
Location
will always be set and won't depend on the type. But this might be impossible to change now. I'm not sure if it'd make sense to throw a custom error if the URL parameter was forgotten.Maybe it'd also be enough to rely on the number of arguments instead of their type.
System information
The text was updated successfully, but these errors were encountered: