Skip to content

[node] Fix http.createServer signature (again) #70455

Merged
typescript-bot merged 15 commits intoDefinitelyTyped:masterfrom
Lordfirespeed:fix/http-prototypes
Sep 25, 2024
Merged

[node] Fix http.createServer signature (again) #70455
typescript-bot merged 15 commits intoDefinitelyTyped:masterfrom
Lordfirespeed:fix/http-prototypes

Conversation

@Lordfirespeed
Copy link
Contributor

@Lordfirespeed Lordfirespeed commented Sep 5, 2024

I am changing an existing definition

This contains all changes from #70289 with the difference that the defaults for the Response type parameters are left unchanged.
This should ensure no existing code is broken.

@Lordfirespeed
Copy link
Contributor Author

Lordfirespeed commented Sep 5, 2024

Usual case
import * as http from "node:http"

export const createServer = () => {
  return http.createServer();
}

Emits declaration:

import * as http from "node:http";
export declare const createServer: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
Case with custom prototypes
import * as http from "node:http"

class Request extends http.IncomingMessage {}

class Response<Req extends Request> extends http.ServerResponse<Req> {}

export const createServer = () => {
  return http.createServer<typeof Request, typeof Response>();
}

Emits declaration:

import * as http from "node:http";
declare class Request extends http.IncomingMessage {}
declare class Response<Req extends Request> extends http.ServerResponse<Req> {}
export declare const createServer: () => http.Server<typeof Request, typeof Response>;
export {};

@Lordfirespeed
Copy link
Contributor Author

@andrewbranch If you have time, I would really appreciate your review on this ❤️

@Lordfirespeed Lordfirespeed changed the title [node] Fix http.createServer (again) [node] Fix http.createServer signature (again) Sep 5, 2024
@Lordfirespeed
Copy link
Contributor Author

Lordfirespeed commented Sep 5, 2024

First check failure is a test I need to adjust, as the type being asserted upon was previously not generic.

Second check failure looks to be a problem on master that went under the radar related to mongoose-delete

@Lordfirespeed
Copy link
Contributor Author

@jakebailey I'm afraid you're my only port of call for ecosystem breaks 😅 please do let me know if you'd prefer I not ping you like this

@Lordfirespeed Lordfirespeed marked this pull request as ready for review September 5, 2024 12:50
@typescript-bot
Copy link
Contributor

typescript-bot commented Sep 5, 2024

@Lordfirespeed Thank you for submitting this PR!

This is a live comment that I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by a DT maintainer

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": 70455,
  "author": "Lordfirespeed",
  "headCommitOid": "35cd007c18de6b6cca94d0ea37483f69b99f1eff",
  "mergeBaseOid": "7a5210ab6680efcb9d2aba9128ce4418974e9638",
  "lastPushDate": "2024-09-05T04:03:59.000Z",
  "lastActivityDate": "2024-09-25T00:21:57.000Z",
  "mergeOfferDate": "2024-09-25T00:20:40.000Z",
  "mergeRequestDate": "2024-09-25T00:21:57.000Z",
  "mergeRequestUser": "Lordfirespeed",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "node",
      "kind": "edit",
      "files": [
        {
          "path": "types/node/http.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/http2.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/https.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/test/http.ts",
          "kind": "test"
        },
        {
          "path": "types/node/test/http2.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v16/http.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/http2.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/https.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v16/test/http2.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v18/http.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/http2.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/https.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v18/test/http2.ts",
          "kind": "test"
        },
        {
          "path": "types/node/v20/http.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v20/http2.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v20/https.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/node/v20/test/http2.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "Microsoft",
        "jkomyno",
        "alvis",
        "r3nya",
        "btoueg",
        "smac89",
        "touffy",
        "DeividasBakanas",
        "eyqs",
        "Hannes-Magnusson-CK",
        "hoo29",
        "kjin",
        "ajafff",
        "islishude",
        "mwiktorczyk",
        "mohsen1",
        "galkin",
        "parambirs",
        "eps1lon",
        "ThomasdenH",
        "WilcoBakker",
        "wwwy3y3",
        "samuela",
        "kuehlein",
        "bhongy",
        "chyzwar",
        "trivikr",
        "yoursunny",
        "qwelias",
        "ExE-Boss",
        "peterblazejewicz",
        "addaleax",
        "victorperin",
        "ZYSzys",
        "NodeJS",
        "LinusU",
        "wafuwafu13",
        "mcollina",
        "Semigradsky"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "jakebailey",
      "date": "2024-09-25T00:16:59.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 2331574541,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Contributor

@typescript-bot
Copy link
Contributor

@Lordfirespeed The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds that are failing do not end up on the list of PRs for the DT maintainers to review.

@Lordfirespeed
Copy link
Contributor Author

Found the ecosystem break: Automattic/mongoose#14863

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Sep 7, 2024
@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label Sep 16, 2024
@typescript-bot
Copy link
Contributor

@typescript-bot
Copy link
Contributor

@jakebailey
Copy link
Member

Is mongoose guaranteed to not break this time?

@Lordfirespeed
Copy link
Contributor Author

Lordfirespeed commented Sep 23, 2024

Is mongoose guaranteed to not break this time?

Mongoose was never breaking because of this PR's (or the previous one's) changes 😅
In fact, this PR's CI was failing because of a breaking change to Mongoose's types.

That said, express and anything using http.createServer without generic type parameters were broken by the previous PR.

I have very high confidence they are not broken by this PR, because it does not change the generic type parameter defaults, just the constraints applied to the generic type parameters when supplied.

So

  • when no type parameters are supplied: it works (because the current generic type parameter defaults work, and are unchanged)
  • when two type parameters are supplied: it works (by design & intent of the PR)

The only potential breaking change I envision is one where someone is supplying only one generic type parameter to http.createServer:

const server = http.createServer<typeof MyRequest>(...)

But we can test that this is not an issue:

class Foo {}

class Bar<T extends Foo = Foo> {}

function createServer<
  TFoo extends typeof Foo = typeof Foo,
  TBar extends typeof Bar<TFoo> = typeof Bar,
>(listener: (foo: TFoo, bar: TBar) => void) {}

class MyFoo extends Foo {}

createServer<typeof MyFoo>((foo, bar) => {})

@jakebailey
Copy link
Member

I retested Andrew's example from #70289 (comment), and the dts emit is now the same before/after this PR, so that issue is also fixed.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Willing to try this a second time given the extra testing we did.

@jakebailey
Copy link
Member

Er, well, you may want to merge master and just verify that things work.

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Sep 24, 2024
@typescript-bot typescript-bot removed the Self Merge This PR can now be self-merged by the PR author or an owner label Sep 25, 2024
@typescript-bot typescript-bot added the Self Merge This PR can now be self-merged by the PR author or an owner label Sep 25, 2024
@typescript-bot
Copy link
Contributor

@Lordfirespeed: Everything looks good here. I am ready to merge this PR (at 35cd007) on your behalf whenever you think it's ready.

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! ❤️

(@microsoft, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @galkin, @parambirs, @eps1lon, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @ZYSzys, @nodejs, @LinusU, @wafuwafu13, @mcollina, @Semigradsky: you can do this too.)

@Lordfirespeed
Copy link
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit 7a8b62b into DefinitelyTyped:master Sep 25, 2024
alino20 pushed a commit to alino20/DefinitelyTyped that referenced this pull request Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Critical package Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants