Skip to content

@my-swu/simulator-client


@my-swu/simulator-client / PromptShape

Type Alias: PromptShape ​

PromptShape = { [K in Exclude<PromptState, string> as keyof K]?: K[keyof K] }

Defined in: packages/ts-sdk/src/types.ts:226

The SDK exposes PromptState as a tagged union ("lobbyReady" | { mulligan: … } | …), which is correct but inconvenient for UIs that walk every prompt variant with optional chaining and gate each branch with a separate if (prompt.chooseAbilityCards) { … }.

PromptShape flattens the union into a record where every variant is an optional field. Consumers can read prompt.chooseAbilityCards without first narrowing through the discriminator. Cast a runtime PromptState to PromptShape at the boundary of UI code:

ts
import type { PromptShape, PromptState } from "@my-swu/simulator-client";
const promptState: PromptState = {
  chooseAbilityCards: { abilityId: 1, max: 1, min: 1, seat: "one" },
};
const promptView = promptState as PromptShape;
if (promptView.chooseAbilityCards) {
  // … access promptView.chooseAbilityCards.{abilityId,max,min,seat}
}

This is unsafe for fan-out narrowing (you can read every field on the "lobbyReady" branch and TypeScript won't catch it), so prefer the discriminated union when you need exhaustiveness checking.

Example:

ts
import type { PromptShape } from '@my-swu/simulator-client'

const promptShape: PromptShape = {}

console.log(promptShape)

Released under the MIT License.