Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions types/node-red__registry/node-red__registry-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import registry = require("@node-red/registry");
import http = require("node:http");

function registryTests() {
interface ExtendedNodeRedSettings extends registry.NodeAPISettingsWithData {
Expand Down Expand Up @@ -165,8 +166,8 @@ function registryTests() {
RED.httpNode;
// $ExpectType Express
RED.httpAdmin;
// $ExpectType Server<typeof IncomingMessage, typeof ServerResponse>
RED.server;

const server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> = RED.server;

// $ExpectType string
RED._("myNode.label");
Expand Down
10 changes: 5 additions & 5 deletions types/node/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ declare module "http" {
}
interface ServerOptions<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
> {
/**
* Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
Expand Down Expand Up @@ -315,14 +315,14 @@ declare module "http" {
}
type RequestListener<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
> = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
/**
* @since v0.1.17
*/
class Server<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
> extends NetServer {
constructor(requestListener?: RequestListener<Request, Response>);
constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
Expand Down Expand Up @@ -1553,11 +1553,11 @@ declare module "http" {
*/
function createServer<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
>(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
function createServer<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
>(
options: ServerOptions<Request, Response>,
requestListener?: RequestListener<Request, Response>,
Expand Down
331 changes: 254 additions & 77 deletions types/node/http2.d.ts

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions types/node/https.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ declare module "https" {
import { URL } from "node:url";
type ServerOptions<
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
Response extends typeof http.ServerResponse = typeof http.ServerResponse,
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
InstanceType<Request>
>,
> = tls.SecureContextOptions & tls.TlsOptions & http.ServerOptions<Request, Response>;
type RequestOptions =
& http.RequestOptions
Expand All @@ -34,15 +36,19 @@ declare module "https" {
}
interface Server<
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
Response extends typeof http.ServerResponse = typeof http.ServerResponse,
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
InstanceType<Request>
>,
> extends http.Server<Request, Response> {}
/**
* See `http.Server` for more information.
* @since v0.3.4
*/
class Server<
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
Response extends typeof http.ServerResponse = typeof http.ServerResponse,
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
InstanceType<Request>
>,
> extends tls.Server {
constructor(requestListener?: http.RequestListener<Request, Response>);
constructor(
Expand Down Expand Up @@ -119,25 +125,19 @@ declare module "https" {
emit(
event: "checkContinue",
req: InstanceType<Request>,
res: InstanceType<Response> & {
req: InstanceType<Request>;
},
res: InstanceType<Response>,
): boolean;
emit(
event: "checkExpectation",
req: InstanceType<Request>,
res: InstanceType<Response> & {
req: InstanceType<Request>;
},
res: InstanceType<Response>,
): boolean;
emit(event: "clientError", err: Error, socket: Duplex): boolean;
emit(event: "connect", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean;
emit(
event: "request",
req: InstanceType<Request>,
res: InstanceType<Response> & {
req: InstanceType<Request>;
},
res: InstanceType<Response>,
): boolean;
emit(event: "upgrade", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean;
on(event: string, listener: (...args: any[]) => void): this;
Expand Down Expand Up @@ -312,11 +312,15 @@ declare module "https" {
*/
function createServer<
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
Response extends typeof http.ServerResponse = typeof http.ServerResponse,
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
InstanceType<Request>
>,
>(requestListener?: http.RequestListener<Request, Response>): Server<Request, Response>;
function createServer<
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
Response extends typeof http.ServerResponse = typeof http.ServerResponse,
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse<
InstanceType<Request>
>,
>(
options: ServerOptions<Request, Response>,
requestListener?: http.RequestListener<Request, Response>,
Expand Down
7 changes: 6 additions & 1 deletion types/node/test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ import * as url from "node:url";
}

class MyServerResponse<
Request extends http.IncomingMessage = http.IncomingMessage,
Request extends MyIncomingMessage = MyIncomingMessage,
> extends http.ServerResponse<Request> {
bar: typeof bar;

getFoo() {
return this.req.foo;
}
}

function reqListener(req: MyIncomingMessage, res: MyServerResponse): void {}
Expand All @@ -75,6 +79,7 @@ import * as url from "node:url";
foo = req.foo;
bar = res.bar;
foo = res.req.foo;
foo = res.getFoo();
});
server = new http.Server({ IncomingMessage: MyIncomingMessage, ServerResponse: MyServerResponse }, reqListener);

Expand Down
6 changes: 4 additions & 2 deletions types/node/test/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ import { URL } from "node:url";
foo: number;
}

class MyHttp2ServerResponse extends Http2ServerResponse {
class MyHttp2ServerResponse<Request extends Http2ServerRequest = Http2ServerRequest>
extends Http2ServerResponse<Request>
{
bar: string;
}

Expand Down Expand Up @@ -485,7 +487,7 @@ import { URL } from "node:url";
const http2Stream: Http2Stream = {} as any;
const duplex: Duplex = http2Stream;

performServerHandshake(duplex, serverOptions); // $ExpectType ServerHttp2Session
const session: ServerHttp2Session = performServerHandshake(duplex, serverOptions);
}

// constants
Expand Down
15 changes: 9 additions & 6 deletions types/node/v16/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ declare module "http" {
}
interface ServerOptions<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
> {
IncomingMessage?: Request | undefined;
ServerResponse?: Response | undefined;
Expand Down Expand Up @@ -265,14 +265,14 @@ declare module "http" {
}
type RequestListener<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
> = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
/**
* @since v0.1.17
*/
class Server<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
> extends NetServer {
constructor(requestListener?: RequestListener<Request, Response>);
constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
Expand Down Expand Up @@ -1287,12 +1287,15 @@ declare module "http" {
*/
function createServer<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
>(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
function createServer<
Request extends typeof IncomingMessage = typeof IncomingMessage,
Response extends typeof ServerResponse = typeof ServerResponse,
>(options: ServerOptions, requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse<InstanceType<Request>>,
>(
options: ServerOptions<Request, Response>,
requestListener?: RequestListener<Request, Response>,
): Server<Request, Response>;
// although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
// create interface RequestOptions would make the naming more clear to developers
interface RequestOptions extends ClientRequestArgs {}
Expand Down
Loading