Skip to content

[DX-1204] Fix v1-callback overloads breaking mocks (never → void)#2239

Merged
umair-ably merged 1 commit into
mainfrom
DX-1204/fix-v1-callback-overload-types
Jun 8, 2026
Merged

[DX-1204] Fix v1-callback overloads breaking mocks (never → void)#2239
umair-ably merged 1 commit into
mainfrom
DX-1204/fix-v1-callback-overload-types

Conversation

@umair-ably

@umair-ably umair-ably commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Background

#2226 (DX-1204) re-introduced the v1 callback-style method signatures as @deprecated overloads returning never, to steer users/LLMs toward the v2 promise API. The runtime guard (detectV1Callback, which throws a hinted error) is the part the PR's evidence measured, and it is not changed here.

@owenpearson reported that the never return type makes these methods impossible to mock by assignment — a common testing pattern:

channel.subscribe = vi.fn(() => Promise.reject()); // ❌ doesn't type-check on main

This fails because the assigned value must satisfy every overload, including the one returning never, and nothing is assignable to a never-returning signature.

Fix

Change the return type of the 14 deprecated v1-callback overloads from nevervoid (auth authorize/createTokenRequest/requestToken, presence get/history/subscribe/enter/update/leave, channel unsubscribe/history/subscribe/publish, connection.ping).

TypeScript allows a function returning any value to be assigned to a void-returning function type (the rule that makes arr.forEach(x => arr.push(x)) legal), so mock assignment now type-checks. never was the only return type that rejected it. (void also matches what these methods returned in v1.)

Diff is 14 lines — ): never;): void; — nothing else.

Intentionally out of scope: the no-deprecated warning on bare references

Owen also noted that @typescript-eslint/no-deprecated flags bare references like expect(channel.subscribe). We are not addressing that here. It's arguably an upstream issue: for a non-call reference the rule can't resolve a specific overload, so it treats the symbol as deprecated if any overload is. Removing the @deprecated tag would silence it but would also drop the editor strikethrough + migration hint on v1 call sites, which we want to keep. Consumers hitting the warning can disable the rule on those lines until it's fixed upstream.

Verification

  • npx tsc --noEmit ably.d.ts modular.d.ts (the check CI gate), prettier --check, and eslint all pass.
  • Mock assignment compiles for all 14 methods (verified against the real ably.d.ts with vitest and @types/jest): vi.fn(...), vi.fn(), jest.fn(...), jest.spyOn, direct assignment.
  • The @deprecated strikethrough + migration hint on v1 call sites are unchanged.
  • Runtime detectV1Callback guard and its tests are unchanged.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected TypeScript type definitions for deprecated callback-based method overloads affecting authentication, realtime presence, channels, and connections. Return type annotations have been updated to more accurately reflect method behavior, enhancing type safety, improving IDE autocompletion accuracy, and reducing type-related issues for TypeScript developers using callback-style APIs.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ee8fbfe2-5597-4bd5-8be1-f57bb81d4ce7

📥 Commits

Reviewing files that changed from the base of the PR and between 402e5e1 and e087e9d.

📒 Files selected for processing (1)
  • ably.d.ts

Walkthrough

The PR updates the Ably JavaScript SDK TypeScript definitions to change deprecated v1 callback-based method overload return types from never to void across multiple classes including Auth, RealtimePresence, RealtimeChannel, and Connection.

Changes

Deprecated v1 Callback Overload Return Types

Layer / File(s) Summary
Auth callback method overloads
ably.d.ts
authorize, createTokenRequest, and requestToken callback overloads return type changed from never to void.
RealtimePresence callback method overloads
ably.d.ts
get, history, subscribe, enter, update, and leave callback overloads return type changed from never to void.
RealtimeChannel callback method overloads
ably.d.ts
unsubscribe, history, subscribe, and publish callback overloads return type changed from never to void.
Connection callback method overload
ably.d.ts
ping callback overload return type changed from never to void.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit hops through types so grand,
From never void, with steady hand,
Callbacks dance in patterns true,
Six classes blessed, their defs made new! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing v1-callback overloads by changing their return type from 'never' to 'void', with reference to the issue number and the core problem (breaking mocks).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DX-1204/fix-v1-callback-overload-types

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot temporarily deployed to staging/pull/2239/bundle-report June 8, 2026 13:50 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2239/typedoc June 8, 2026 13:50 Inactive
@umair-ably umair-ably force-pushed the DX-1204/fix-v1-callback-overload-types branch from cefc96a to 5b00bbb Compare June 8, 2026 13:53
@github-actions github-actions Bot temporarily deployed to staging/pull/2239/bundle-report June 8, 2026 13:53 Inactive
@github-actions github-actions Bot temporarily deployed to staging/pull/2239/typedoc June 8, 2026 13:54 Inactive
@umair-ably umair-ably requested review from AndyTWF and owenpearson June 8, 2026 13:54

@owenpearson owenpearson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the change to void is good! i don't like the other one though, sorry:

Comment thread ably.d.ts
PR #2226 added @deprecated v1-callback overloads returning `never`. The `never`
return made these methods impossible to mock by assignment (e.g.
`channel.subscribe = vi.fn(() => Promise.reject())`), because nothing is
assignable to a `never`-returning signature.

Change the return type of the 14 deprecated v1-callback overloads from `never`
to `void`. A function returning any value is assignable to a `void`-returning
function type, so mock assignment now type-checks; `never` was the only return
type that rejected it.

The @deprecated tag is kept, so the editor strikethrough and migration hint on
v1 call sites are unchanged. This intentionally does NOT address the
@typescript-eslint/no-deprecated warning on bare references (e.g.
`expect(channel.subscribe)`) — that is arguably an upstream issue (the rule
treats an overloaded symbol as deprecated if any one overload is, even for
non-call references). Consumers can disable the rule on those lines until it's
addressed upstream.

Runtime detectV1Callback guard and its tests are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@umair-ably umair-ably force-pushed the DX-1204/fix-v1-callback-overload-types branch from 5b00bbb to e087e9d Compare June 8, 2026 14:35
@umair-ably umair-ably changed the title [DX-1204] Fix v1-callback overload types (mocking + no-deprecated) [DX-1204] Fix v1-callback overloads breaking mocks (never → void) Jun 8, 2026
@umair-ably umair-ably requested a review from owenpearson June 8, 2026 14:38
@umair-ably umair-ably marked this pull request as ready for review June 8, 2026 14:38
@umair-ably umair-ably merged commit a76bb68 into main Jun 8, 2026
10 of 14 checks passed
@umair-ably umair-ably deleted the DX-1204/fix-v1-callback-overload-types branch June 8, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants