Skip to content

fix: narrow DispatchOptions.upgrade type to string | null#5485

Open
mcollina wants to merge 1 commit into
mainfrom
fix/dispatchOptions-upgrade-type
Open

fix: narrow DispatchOptions.upgrade type to string | null#5485
mcollina wants to merge 1 commit into
mainfrom
fix/dispatchOptions-upgrade-type

Conversation

@mcollina

@mcollina mcollina commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #5466

DispatchOptions.upgrade accepted boolean in the TypeScript type, but the runtime validator in lib/core/request.js rejects any truthy non-string value with InvalidArgumentError: upgrade must be a string. A TypeScript-valid call like client.dispatch({ path: '/', method: 'GET', upgrade: true }, handler) therefore fails at runtime.

Changes

  • types/dispatcher.d.ts: Narrowed upgrade from boolean | string | null to string | null
  • test/types/dispatcher.test-d.ts: Added type-level assertion that upgrade: true is rejected via expectNotAssignable, plus positive assertions for upgrade: 'websocket' and upgrade: null

Testing

  • expectNotAssignable<Dispatcher.DispatchOptions>({ ..., upgrade: true }) — fails at type-check time
  • Existing valid usage (upgrade: 'websocket', upgrade: null) remains accepted

The TypeScript type for DispatchOptions.upgrade included boolean, but
the runtime validator in lib/core/request.js rejects any truthy non-string
value. Narrowing the type to string | null aligns it with the runtime
contract, preventing TypeScript-valid code from failing at runtime.

Fixes #5466
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.45%. Comparing base (ce7bf4f) to head (1e125f0).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5485      +/-   ##
==========================================
- Coverage   93.46%   93.45%   -0.01%     
==========================================
  Files         110      110              
  Lines       37124    37147      +23     
==========================================
+ Hits        34698    34716      +18     
- Misses       2426     2431       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DispatchOptions.upgrade accepts boolean in types but runtime rejects it

4 participants