[DX-1204] Fix v1-callback overloads breaking mocks (never → void)#2239
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR updates the Ably JavaScript SDK TypeScript definitions to change deprecated v1 callback-based method overload return types from ChangesDeprecated v1 Callback Overload Return Types
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
cefc96a to
5b00bbb
Compare
owenpearson
left a comment
There was a problem hiding this comment.
the change to void is good! i don't like the other one though, sorry:
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>
5b00bbb to
e087e9d
Compare
Background
#2226 (DX-1204) re-introduced the v1 callback-style method signatures as
@deprecatedoverloads returningnever, 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
neverreturn type makes these methods impossible to mock by assignment — a common testing pattern:This fails because the assigned value must satisfy every overload, including the one returning
never, and nothing is assignable to anever-returning signature.Fix
Change the return type of the 14 deprecated v1-callback overloads from
never→void(authauthorize/createTokenRequest/requestToken, presenceget/history/subscribe/enter/update/leave, channelunsubscribe/history/subscribe/publish,connection.ping).TypeScript allows a function returning any value to be assigned to a
void-returning function type (the rule that makesarr.forEach(x => arr.push(x))legal), so mock assignment now type-checks.neverwas the only return type that rejected it. (voidalso matches what these methods returned in v1.)Diff is 14 lines —
): never;→): void;— nothing else.Intentionally out of scope: the
no-deprecatedwarning on bare referencesOwen also noted that
@typescript-eslint/no-deprecatedflags bare references likeexpect(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@deprecatedtag 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(thecheckCI gate),prettier --check, andeslintall pass.ably.d.tswithvitestand@types/jest):vi.fn(...),vi.fn(),jest.fn(...),jest.spyOn, direct assignment.@deprecatedstrikethrough + migration hint on v1 call sites are unchanged.detectV1Callbackguard and its tests are unchanged.🤖 Generated with Claude Code
Summary by CodeRabbit