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
koa: fix: Callback type to be compatible with node #48622
Conversation
See definition of RequestListener at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/http.d.ts#L115 The actual Koa code at https://github.com/koajs/koa/blob/master/lib/application.js#L168 does return a promise, but one that's already had both `then` and `catch` called upon it.
@kf6kjg Thank you for submitting this PR! This is a live comment which I will keep updated. This PR doesn't modify any tests, so it's hard to know what's being fixed, and your changes might regress in the future. Have you considered adding tests to cover the change you're making? Including tests allows this PR to be merged by yourself and the owners of this module. This can potentially save days of time for you. 1 package in this PRCode ReviewsThis PR can be merged once it's reviewed. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 48622,
"author": "kf6kjg",
"owners": [
"DavidCai1993",
"jkeylu",
"brikou",
"harryparkdotio",
"chatoo2412"
],
"dangerLevel": "ScopedAndUntested",
"headCommitAbbrOid": "02f3825",
"headCommitOid": "02f3825120d8ebfa4000cfd67ca1e5137cf7099b",
"mergeIsRequested": true,
"stalenessInDays": 0,
"lastPushDate": "2020-10-08T18:11:31.000Z",
"lastCommentDate": "2020-10-20T14:42:51.000Z",
"maintainerBlessed": true,
"reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/48622/files",
"hasMergeConflict": false,
"authorIsOwner": false,
"isFirstContribution": false,
"popularityLevel": "Popular",
"newPackages": [],
"packages": [
"koa"
],
"files": [
{
"path": "types/koa/index.d.ts",
"kind": "definition",
"package": "koa"
}
],
"hasDismissedReview": false,
"ciResult": "pass",
"lastReviewDate": "2020-10-17T01:04:28.000Z",
"firstApprovalDate": "2020-10-17T01:04:28.000Z",
"reviewersWithStaleReviews": [],
"approvalFlags": 2,
"isChangesRequested": false
} |
🔔 @DavidCai1993 @jkeylu @brikou @harryparkdotio @chatoo2412 — please review this PR in the next few days. Be sure to explicitly select |
Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files. koa (unpkg)was missing the following properties:
|
👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let’s review the numbers, shall we? Comparison details 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. |
Ping 🔔 @DavidCai1993 @jkeylu @brikou @harryparkdotio @chatoo2412 |
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.
The actual Koa code at https://github.com/koajs/koa/blob/master/lib/application.js#L168 does return a promise, but one that's already had both then and a generic catch called upon it.
The response of the callback
method is still a function which returns a Promise, having called then
and catch
on the Promise doesn't change the return type from being a Promise.
However, the function that callback
returns (essentially a RequestListener), still handles a request using a callback style approach (which makes sense, given that the node RequestListener is a callback). This means that the Koa callback RequestListener, while it is still returning a Promise, the resolution of that Promise is bound to the middleware stack and is unrelated to the http callback. This is likely due to the need of resolving the entire middleware chain prior to initiating the http response callback.
While the Koa code does still return a Promise, I think this Promise is an internal concern incorrectly being exposed, and so treating callback
as if nothing was returned (void
) seems both valid and rational to me.
@kf6kjg Everything looks good here. Great job! I am ready to merge this PR on your behalf. If you'd like that to happen, please post a comment saying:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@DavidCai1993, @jkeylu, @brikou, @harryparkdotio, @chatoo2412: you can do this too.) |
Ready to merge |
I just published |
See definition of RequestListener at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/http.d.ts#L115
The actual Koa code at https://github.com/koajs/koa/blob/master/lib/application.js#L168 does return a promise, but one that's already had both
then
and a genericcatch
called upon it.Please fill in this template.
npm test YOUR_PACKAGE_NAME
.)npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If changing an existing definition:
tslint.json
containing{ "extends": "dtslint/dt.json" }
. If for reason the any rule need to be disabled, disable it for that line using// tslint:disable-next-line [ruleName]
and not for whole package so that the need for disabling can be reviewed.