Skip to content

Comments

Add generic type parameter for Round state#4

Open
giokaxo wants to merge 1 commit intoStakeEngine:mainfrom
giokaxo:feat/generic-round-state
Open

Add generic type parameter for Round state#4
giokaxo wants to merge 1 commit intoStakeEngine:mainfrom
giokaxo:feat/generic-round-state

Conversation

@giokaxo
Copy link

@giokaxo giokaxo commented Feb 21, 2026

Summary

  • Add generic type parameter <T = unknown> to Round, PlayResponse, AuthenticateResponse, Client, and RGSClient
  • Allows consumers to specify the type of round.state instead of it being hardcoded to unknown
  • Fully backwards compatible — defaults to unknown when no type argument is provided

Problem

The Round.state field was typed as unknown, requiring consumers to manually cast the state on every access:

const client = RGSClient({ url: '...' });
const res = await client.Play({ amount: 100, mode: 'base' });
const state = res.round.state as MyGameState; // manual cast needed every time

Solution

The generic parameter flows end-to-end from RGSClient<T> through Client<T>, AuthenticateResponse<T>, PlayResponse<T>, and Round<T>:

type MyGameState = { reels: number[][]; multiplier: number };

const client = RGSClient<MyGameState>({ url: '...' });
const res = await client.Play({ amount: 100, mode: 'base' });
res.round.state.reels;      // number[][] — fully typed
res.round.state.multiplier;  // number — fully typed

Test plan

  • Verify the build completes without type errors
  • Confirm existing consumers without type arguments still compile (backwards compatible via = unknown default)
  • Test that specifying a type argument correctly narrows round.state

🤖 Generated with Claude Code

The `Round.state` field was typed as `unknown`, forcing consumers to
cast manually. This adds a generic `<T = unknown>` to `Round`,
`PlayResponse`, `AuthenticateResponse`, `Client`, and `RGSClient` so
the state type can be specified once and flow through the entire API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant