-
-
Notifications
You must be signed in to change notification settings - Fork 35
fix(response): use never return type for abort method #13
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
Conversation
/cc @thetutlage |
Ping. Even if we don't find a solution for |
Yeah, we need inverse of |
Do you want me to add that to this PR? |
Yeah, let's get them out together |
This method is the inverse of abortIf. It allows to use type assertions to make TypeScript narrow types if the function threw.
Done. |
test('abortUnless: abort request when condition is falsy', async (assert) => { | ||
const server = createServer((req, res) => { | ||
const config = fakeConfig() | ||
const response: Response = new Response(req, res, config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See microsoft/TypeScript#33622
It is necessary here to explicitly declare the type of Response
. In practice in Adonis, the type is already defined in the context so the user doesn't have to do anything.
Example with the change, where TS correctly determined that the code after the call is unreachable:
Thanks 😄 |
I tried to use the new feature that TypeScript added for assertions functions to fix the type of
abortIf
but couldn't find a way.abortIf
is implemented in the opposite way (throws if the condition is truthy) than usual assertions.Ref: https://devblogs.microsoft.com/typescript/announcing-typescript-3-7/#assertion-functions