[@types/node] v18.7.16 breaks in union of http and https createServer types (TS2349)
#62170
-
|
Hello! I'd like to get some more context on the changes introduced by v18.7.16. We are seeing errors with v18.7.16 of this package come up in our CI/CD. Reverting to 18.7.15 makes the errors go away. The errors seem to be related to these line in our code where we're trying to make a union of the built in http and https functions // importing `createServer` from `http` and `https`
import { createServer, Server, ServerOptions } from 'http';
import { createServer as createHttpsServer, Server as HTTPSServer, ServerOptions as HTTPSServerOptions } from 'https';
// union type
let createServerFn: typeof createServer | typeof createHttpsServer = createServer;
// evoking createServerFn as a function
this.server = createServerFn(serverOptions, this.app);Is this intentional or unintentionally breaking? If the former, is there a recommended way to resolve this issue? Full Error log: Repro: |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
|
Thanks for the discussion about "node", some useful links for everyone: Pinging the DT module owners: @microsoft, @DefinitelyTyped, @jkomyno, @alvis, @r3nya, @btoueg, @smac89, @Touffy, @DeividasBakanas, @eyqs, @Hannes-Magnusson-CK, @hoo29, @kjin, @ajafff, @islishude, @mwiktorczyk, @mohsen1, @n-e, @galkin, @parambirs, @eps1lon, @SimonSchick, @ThomasdenH, @WilcoBakker, @wwwy3y3, @samuela, @kuehlein, @bhongy, @chyzwar, @trivikr, @yoursunny, @qwelias, @ExE-Boss, @peterblazejewicz, @addaleax, @victorperin, @ZYSzys, @nodejs, @LinusU, @wafuwafu13, @mcollina. |
Beta Was this translation helpful? Give feedback.
-
|
@srajiang I think this is outcome of the changes from this PR: #61922 |
Beta Was this translation helpful? Give feedback.
-
@srajiang Could you please provide a complete code snippet to reproduce the problem? The following // union type
let createServerFn: typeof http.createServer | typeof https.createServer = http.createServer;
// Custom IncomingMessage
let foo: 'foo';
class MyIncomingMessage extends http.IncomingMessage {
foo: typeof foo;
}
let serverOptions = { IncomingMessage: MyIncomingMessage, insecureHTTPParser: true };
createServerFn(serverOptions, (req, res) => {
foo = req.foo;
foo = res.req.foo;
});works just fine. |
Beta Was this translation helpful? Give feedback.
-
|
Sure thing @vansergen - and a start method public start(
portOrListenOptions: number | ListenOptions,
serverOptions: ServerOptions | HTTPSServerOptions = {},
): Promise<Server | HTTPSServer> {
let createServerFn: typeof createServer | typeof createHttpsServer = createServer;
// Look for HTTPS-specific serverOptions to determine which factory function to use
if (Object.keys(serverOptions).filter((k) => httpsOptionKeys.includes(k)).length > 0) {
createServerFn = createHttpsServer;
}
if (this.server !== undefined) {
return Promise.reject(
new ReceiverInconsistentStateError('The receiver cannot be started because it was already started.'),
);
}
this.server = createServerFn(serverOptions, this.app);
// handle return promise below
// ... |
Beta Was this translation helpful? Give feedback.
Sure thing @vansergen -
I have a class constructor setting up
and a start method