Skip to content
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

Merged
merged 1 commit into from Oct 20, 2020

Conversation

kf6kjg
Copy link
Contributor

@kf6kjg kf6kjg commented Oct 8, 2020

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 generic catch called upon it.

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • [N/A] Add or edit tests to reflect the change. (Run with npm test YOUR_PACKAGE_NAME.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: See above.
  • [N/A] If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.
  • Include tests for your changes
  • [N/A] If you are making substantial changes, consider adding a 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.

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.
@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Untested Change This PR does not touch tests labels Oct 8, 2020
@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board Oct 8, 2020
@typescript-bot
Copy link
Contributor

typescript-bot commented Oct 8, 2020

@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 PR

Code Reviews

This PR can be merged once it's reviewed.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

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
}

@typescript-bot
Copy link
Contributor

🔔 @DavidCai1993 @jkeylu @brikou @harryparkdotio @chatoo2412 — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@danger-public
Copy link

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

koa (unpkg)

was missing the following properties:

  1. once
  2. EventEmitter

Generated by 🚫 dangerJS against 02f3825

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Oct 8, 2020
@typescript-bot
Copy link
Contributor

👋 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 📊
master #48622 diff
Batch compilation
Memory usage (MiB) 70.5 71.1 +0.8%
Type count 10472 10472 0%
Assignability cache size 1805 1805 0%
Language service
Samples taken 200 200 0%
Identifiers in tests 200 200 0%
getCompletionsAtPosition
    Mean duration (ms) 439.0 434.4 -1.0%
    Mean CV 8.6% 8.3%
    Worst duration (ms) 539.7 540.7 +0.2%
    Worst identifier Error listen
getQuickInfoAtPosition
    Mean duration (ms) 441.1 436.6 -1.0%
    Mean CV 8.2% 8.3% +1.6%
    Worst duration (ms) 551.5 560.0 +1.5%
    Worst identifier listen app

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Oct 8, 2020
@orta
Copy link
Collaborator

orta commented Oct 16, 2020

Ping 🔔 @DavidCai1993 @jkeylu @brikou @harryparkdotio @chatoo2412

Copy link
Contributor

@harryparkdotio harryparkdotio left a 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.

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label Oct 17, 2020
@elibarzilay elibarzilay moved this from Needs Maintainer Review to Waiting for Author to Merge in New Pull Request Status Board Oct 20, 2020
@typescript-bot typescript-bot added the Self Merge This PR can now be self-merged by the PR author or an owner label Oct 20, 2020
@typescript-bot
Copy link
Contributor

@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:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@DavidCai1993, @jkeylu, @brikou, @harryparkdotio, @chatoo2412: you can do this too.)

@kf6kjg
Copy link
Contributor Author

kf6kjg commented Oct 20, 2020

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Oct 20, 2020
@typescript-bot typescript-bot merged commit 02ec426 into DefinitelyTyped:master Oct 20, 2020
@kf6kjg kf6kjg deleted the patch-1 branch October 20, 2020 14:44
@typescript-bot
Copy link
Contributor

I just published @types/koa@2.11.6 to npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Popular package This PR affects a popular package (as counted by NPM download counts). Self Merge This PR can now be self-merged by the PR author or an owner Untested Change This PR does not touch tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants