Repository navigation
feat(plugin-gateway): register the client as a typed container.gatewayClient - #130
Conversation
…ent` `container.client` is typed by `@wolfstar/http-framework` as the base `Client`, so pieces had to call `getGatewayClient()` or cast to reach `guilds`, `members`, `gateway` & co. Retyping it is not possible: a module augmentation redeclaring `Container.client` as `GatewayClient` fails with TS2717, and under `skipLibCheck` the error is hidden while the framework's `Client` still wins (checked with TypeScript 7.0.2 and 5.6, from a published `.d.ts` and from the consumer's own sources). `GatewayClient` now registers itself as `container.gatewayClient`, declared on the `Container` of `@sapphire/pieces` like plugin-api's `server` and plugin-i18next's `i18n`. It is a new name, so it type-checks with and without `skipLibCheck` and leaves `container.client` untouched for plain clients. A type-level consumption test, wired into `pnpm typecheck`, enforces both. Refs #121 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RBWEHLtNzWNykJMPqeqqbB
◈ PR Lens
Architecture 2 components touched across 6 lanes. Play the interactive walkthrough Data flow No data-flow sequence changed in this PR. View
Tip Click the link under each diagram to open it on a canvas you can zoom, pan and step through 🪧 More tips
Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the full diff: GatewayClient now registers itself as a typed container.gatewayClient, alongside supporting docs, tests, and tooling wiring.
container.gatewayClientaugmentation (src/util/container.ts): declaresgatewayClient: GatewayClienton@sapphire/pieces'sContainer, matching the existing pattern used byplugin-api'sserverandplugin-i18next'si18n.GatewayClientconstructor: setscontainer.gatewayClient = thisright aftersuper(), next to the framework's owncontainer.clientassignment.- Type-level consumption test (
tests/types/container.ts) + newtsconfig.consumption.json, wired into the roottypecheckscript: asserts typed access from aListener/Command, and a@ts-expect-errorthatcontainer.clientstill lacks managers. - Runtime test: extends the existing
container.clientassertion to also checkcontainer.gatewayClient. knip.jsonignores@sapphire/piecesforplugin-gateway, since the only reference is a baredeclare modulespecifier with noimport.- README + changeset: documents the new access pattern and ships a minor changeset for
@wolfstar/plugin-gateway.
I verified the declare module block's shape against plugin-api/plugin-i18next's existing augmentations (identical convention), confirmed GuildManager is actually exported via the ./managers barrel so the type test compiles against real exports, and confirmed the constructor assignment is safe (JS constructors run synchronously to completion, so there's no window where another piece could observe a half-initialized gatewayClient). container.client is correctly left untouched, and getGatewayClient() is unchanged as stated.
No correctness, security, or convention issues found.
Claude Sonnet | 𝕏

🔗 Linked issue
Part of #121 (item 5:
container.clientstays typed asClient).🧭 Context
@wolfstar/http-frameworktypescontainer.clientas its baseClient. To reachguilds,members,gatewayand the other managers, pieces had to callgetGatewayClient()or cast. The issue suggests an opt-in augmentation that retypescontainer.clientasGatewayClient. TypeScript doesn't allow that. I tested it in a throwaway consumer against the real@wolfstar/http-framework5.1.0 and@sapphire/pieces4.4.1, with TypeScript 7.0.2 and 5.6:skipLibCheck: false, redeclaringContainer.clientin a module augmentation fails with TS2717 ("Property 'client' must be of type 'Client', but here has type 'GatewayClient'").skipLibCheck: truethe error is hidden, but the framework's declaration still wins.container.client.guildsis still TS2339, and assigning it toGatewayClientis TS2322.Containerthrough"@wolfstar/http-framework"doesn't work either. The framework only re-exports thecontainervalue, not theContainertype, so the augmentation would declare an unrelated interface.📚 Description
GatewayClientnow registers itself ascontainer.gatewayClient. The property is declared on@sapphire/pieces'sContainer, the same way plugin-api declaresserverand plugin-i18next declaresi18n. Because it's a new name, it type-checks with and withoutskipLibCheck, has no cost, and leavescontainer.clientunchanged, so plainClientusers are unaffected:Like
container.client, it holds the most recently constructed client.getGatewayClient()is unchanged.I rejected one alternative: merging an interface into the framework's
Clientclass. It compiles, but it would claim every plainClienthas managers, which isn't true. It would also leak into the rootgolar typecheck, which checks every package's sources in one program.Key changes
src/util/container.ts: theContainer.gatewayClient: GatewayClientaugmentation, with a doc comment explaining whycontainer.clientcan't be retyped.src/GatewayClient.ts: the constructor setscontainer.gatewayClient = thisright aftersuper().@sapphire/piecesis added todependencies, as in plugin-api and plugin-i18next, so the augmented module resolves from the published.d.ts.knip.jsonignores it because knip doesn't countdeclare moduleas usage.tsconfig.consumption.jsonandtests/types/container.ts, wired into the roottypecheckscript. They assert typed access from aListenerand aCommand(the README example), and use@ts-expect-errorto check thatcontainer.client.guildsis still rejected. I confirmed the check fails (TS2551) when the augmentation is removed.container.gatewayClient.@wolfstar/plugin-gatewayminor.Type of Change
Pre-flight Checklist
main)pnpm changesetAlso checked:
pnpm lint,pnpm typecheck(including the new consumption project), and the gateway build (attw and publint clean). A scratch consumer compiled against the builtdistpasses withskipLibCheckon and off under TypeScript 7.0.2.🤖 Generated with Claude Code
https://claude.ai/code/session_01RBWEHLtNzWNykJMPqeqqbB
Generated by Claude Code