Repository navigation
fix(eio-client/types): fix the type of the perMessageDeflate option and of send() - #5631
Open
mark1russell7 wants to merge 1 commit into
Open
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
…nd of send()
The perMessageDeflate option can be set to false to disable the
permessage-deflate extension (as stated in its documentation), and its
default value is { threshold: 1024 }.
The send() and write() methods accept a callback as their second
argument at runtime, but their signature did not allow it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The kind of change this PR does introduce
Current behavior
perMessageDeflate?: { threshold: number }:falseis a type error, although the JSDoc says "Set to false to disable.", andthresholdis required. The JSDoc says@default false, but the default is{ threshold: 1024 }.send(msg, options?, fn?)andwrite(msg, options?, fn?):send(msg, fn)is a type error, although the runtime accepts the callback as the second argument.New behavior
perMessageDeflate?: boolean | { threshold?: number }, with@default { threshold: 1024 }.websocket.node.tsreads the threshold through a type assertion (the runtime checkif (this.opts.perMessageDeflate)is unchanged).send()andwrite()get the overloads(msg, fn?)and(msg, options?, fn?)._sendPacket()acceptsWriteOptions | (() => void)as its third argument, which is what it handles at runtime. In its branch for a function,optionsis now set to{}instead ofnull, so that TypeScript narrows it toWriteOptions(thestrictoption is off). The value is the same as before, because the next step isoptions = options || {}.No runtime behavior changes. This widens the type of an option, so code that reads
opts.perMessageDeflate.thresholdfrom the options of a socket now needs a type check.Other information (e.g. related issues)
Fixes #5629
The type tests of the repository are disabled (
test:typesisexit 0), so the types were checked withtsc(strict) on a small file that usesperMessageDeflate: falseandsend("hello", () => {}), against the declarations built frommainand from this branch. The PR also adds a test intest/connection.js("should accept a callback as the second argument of send()") for the runtime behavior that the new overload declares.Test results, from one run on a GitHub Actions runner (Linux, Node.js 24.22.2, TypeScript 6.0.3 of the lock file), at the commit 84d476a of this branch on top of
main(f97d51a). The job followsci-engine.io-client.yml:npm ci, then it compiles engine.io-parser, engine.io-client and engine.io. "Before" is thelib/folder ofmainwith the tests of this branch.tscbefore:check.ts(4,54): error TS2322: Type 'boolean' is not assignable to type '{ threshold: number; }'.andcheck.ts(7,22): error TS2559: Type '() => void' has no properties in common with type 'WriteOptions'.tscafter: no error.npx mocha --exit --require test/support/hooks.js --grep callback test/connection.js: 1 passing before and after, with XHR and withUSE_FETCH=1(the runtime already accepts the callback).test:node110 passing, 1 pending.test:node-fetch109 passing, 2 pending.test:node-builtin-ws107 passing, 4 pending.format:checkpasses.The run: https://github.com/mark1russell7/wirelab/actions/runs/43625189318
This PR was prepared with AI assistance (Claude). The checks named above ran before and after the change in that run, with the results above.
🤖 Generated with Claude Code