fix(cloneIncomingMessage): inherit prototype properties#214
fix(cloneIncomingMessage): inherit prototype properties#214kettanaito merged 5 commits intomswjs:mainfrom
Conversation
99f6c2c to
8dde721
Compare
|
Hey, @hrsh7th! Thank you for submitting this fix.
This may be an issue, as we're exposing the cloned When the consumer adds a Maybe we can think of reusing parts of your solution to preserve the prototype? Would that be possible? |
|
I've tested this locally on node16 re-using the same workflow that the github actions has and it works great! Regarding the types, this function as it existed before and after this PR forces the type by casting to unknown and then to ClonedIncomingMessage. The stream itself has the same overall shape but it now has the prototype methods added in. If you remove the 'to unknown' part tsc has a way better idea about the type of the stream and it seems like it's been the wrong one for quite some time. Like if you look at the shape of an IncomingMessage vs what's there in |
|
I'd changed the implementation to support This approach can be broken if both |
|
I think this PR is ready to review and merge. 👍🏼 |
| expect(clone).toBeInstanceOf(IncomingMessage) | ||
| expect(clone).toBeInstanceOf(EventEmitter) | ||
| expect(clone).toBeInstanceOf(Stream) | ||
| expect(clone).toBeInstanceOf(Readable) |
There was a problem hiding this comment.
I'm adding assertions to check that the cloned message indeed extends all the prototypes of the original message.
kettanaito
left a comment
There was a problem hiding this comment.
Absolutely fantastic job on this one, @hrsh7th! 🎉
Thank you for making this library better. Welcome to contributors!
|
🎉 This PR is included in version 0.13.6 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Thank you for review, fix and merge! 🎉 |
Fix #212
The current implementation will clone the properties defined in
instance.But the
headersproperty defined inprototypein Node.js v16 or higher.So this PR aims to support prototype inheriting in
cloneIncomingMessage.Fixed.