0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「未接続」だけでは伝わらない。TypeScriptで次の操作を表す

0
Posted at

32aa9545-0032-4d2f-8f95-d8b658fe0a9b.png

connected: false では、次に何を表示するか分からない

『猫のPC工房』には「機器 → ケーブル → 接続端子」をたどるガイドがあります。この体験を題材に、UIの状態をどう表すと条件分岐を整理できるかを考えます。以下は説明用の最小例で、ゲーム本体のコードではありません。

type Step =
  | { kind: "choose-device" }
  | { kind: "check-cable"; device: string }
  | { kind: "find-port"; device: string; port: string }
  | { kind: "done"; device: string };

function hint(step: Step): string {
  switch (step.kind) {
    case "choose-device": return "接続する機器を選ぶ";
    case "check-cable": return `${step.device}のケーブルを確認する`;
    case "find-port": return `${step.port}の差し込み口を探す`;
    case "done": return `${step.device}の接続完了`;
  }
}

port は差し込み口を案内する段階でだけ必要です。この型なら、機器を選ぶ前に端子の情報を表示しようとした場合、型チェックで気づけます。表示側は kind に合わせて、強調する場所と短い案内文を一緒に切り替えます。光や色が分かりづらい場合にも、テキストが操作の手掛かりになります。

この方法は、初回設定やチュートリアルにも応用できます。単に完了か未完了かを記録するのではなく、ユーザーが何を済ませ、次に何が必要かを状態にすると、案内の出し分けがしやすくなります。

題材のゲームをブラウザで遊ぶ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?