Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@jonchurch @bjohansebas @clicktodev Could you please take a look at this PR when you get a chance? It’s part of the TypeScript WG initiative, and since we’re members, your input would be valuable. |
bjohansebas
left a comment
There was a problem hiding this comment.
Actually, I think this should be targeted at version 2, since that’s the one being depended on. These changes can be backported to version 3
|
@bjohansebas I recommend merging this into |
|
the advantage of releasing this as a new major release is that people will be more likely to read the patch notes since it's a major release and they will discover that they shouldn't install third party types anymore. |
|
okay, so let's release it as part of version 3 then |
There was a problem hiding this comment.
Had a question about ServerResponse vs OutgoingMessage, which is mostly a nit #69 (comment)
The undefined for error seems off, Im confident it is but not 100%
|
|
||
| declare function onFinished<T extends IncomingMessage | ServerResponse>( | ||
| msg: T, | ||
| listener: (err: Error | null | undefined, msg: T) => void |
There was a problem hiding this comment.
I don't think undefined is possible here.
| listener: (err: Error | null | undefined, msg: T) => void | |
| listener: (err: Error | null, msg: T) => void |
There was a problem hiding this comment.
It’s a behavior I’m seeing in #87 , maybe there’s a bug? I’m still working on migrating those tests to HTTP/2.
There was a problem hiding this comment.
Can you point to a reproduction of the behavior?
There was a problem hiding this comment.
const http2 = require('http2')
const onFinished = require('..')
var server = http2.createServer(function (req, res) {
onFinished(res, function (_err, msg) {
console.log(_err)
assert.strictEqual(msg, res)
server.close(done)
})
})
server.listen(function () {
var port = this.address().port
var client = http2.connect('http://127.0.0.1:' + port)
client.on('error', noop)
client.on('close', noop)
var req = client.request({ ':path': '/' })
req.on('response', function () {})
req.end()
setImmediate(function () {
client.destroy()
})
})There was a problem hiding this comment.
Ah, I keep not checking v3 branch.
This is why typescript rules lol. It's catching a regression in types (or at least a difference, @Phillip9587 wasundefined intentional as a way to differentiate different close scenarios?)
Line 113 in 57ba282
ee-first always normalized the error arg for us to Error | null:
https://github.com/jonathanong/ee-first/blob/master/index.js#L84-L86
When v3 switched to stream.finished(), that normalization was lost. I think we should fix the v3 code to explicitly pass null here (and on line 128 for socket close), keeping the type as Error | null to match v2 behavior.
At least, unless there is a compelling reason to change the behavior, keeping it the same makes sense to me.
There was a problem hiding this comment.
Is undefined a problem here? I updated the types intentionally because it is the actual behaviour after #56. I can update the onFinish function to normalize to null if we want to keep the existing behaviour:
Lines 97 to 101 in 57ba282
But even the stream.finished() callback's error is typed as optional so it includes undefined:
function finished(
stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
callback: (err?: NodeJS.ErrnoException | null) => void,
): () => void;I would prefer not normalizing to null and calling the callback without a parameter.
There was a problem hiding this comment.
I think it’s better to leave it as is, after all, this is just a wrapper around finished(), and this is how Node.js returns it, so we should leave it that way.
Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>
This PR adds type definitions to finalhandler. It includes the following changes:
type,mainandtypesfield topackage.json@tsconfig/node18from https://github.com/tsconfig/bases@arethetypeswrong/cliandexpect-typeand run them in the CI PipelineRef: expressjs/typescript-wg#1
cc @RobinTail