Skip to content

Create types.ts with shared interfaces for P2P messages and card domain #216

@arasaka-net

Description

@arasaka-net

Add a src/scripts/types.ts file defining TypeScript interfaces for the P2P message shapes and the card-info domain object. This gives tsc --noEmit something to validate and provides a single source of truth for data structures used across modules.

Context
Every module in src/scripts/ constructs and consumes P2P messages and card-info objects using ad-hoc object literals. The message shape — { messageType, entityType, entityId, content, perspective } — is repeated across sendCreateMessage, sendGrabMessage, sendMoveMessage, sendUngrabMessage, and receiveMessage with no shared definition. The card-info shape is similarly duplicated: createCard reads cardInfo.title, .side_code, .faction_code, .type_code, .image, while cardElementToCardInfo in deck.js reconstructs the same shape from DOM attributes. A types.ts file would centralize these definitions, making npm run typecheck catch field name typos (the codebase already has cardIfo at game.js:35 and stactedToken at token.js:122), and serves as the foundation for enabling checkJs (#170) and noImplicitAny (#193).

Affected Files

  • src/scripts/types.ts — New file — define interfaces: P2PMessage (with discriminated union on messageType), CardInfo, TokenName (string literal union)
  • src/scripts/p2p.js — Add JSDoc @typedef {import('./types.ts').P2PMessage} or @type annotations on send functions and receiveMessage parameter
  • src/scripts/card.js — Add JSDoc @param {import('./types.ts').CardInfo} cardInfo on createCard
  • src/scripts/deck.js:117 — Add JSDoc return type @returns {import('./types.ts').CardInfo} on cardElementToCardInfo

Requirements

  • src/scripts/types.ts exists and exports at least P2PMessage (or a discriminated union of message subtypes) and CardInfo interfaces
  • CardInfo includes fields title, side_code, faction_code, type_code, image, and optionally code
  • P2PMessage captures the messageType, entityType, entityId, content, and perspective fields with appropriate types
  • npm run typecheck passes with the new file in place
  • At least createCard in card.js and receiveMessage in p2p.js reference the new types via JSDoc annotations

Verification

  • npm run typecheck
  • npm run lint
  • test -f src/scripts/types.ts && echo 'types.ts exists'

Not In Scope

Evidence

  • src/scripts/p2p.js:9-17sendCreateMessage builds { perspective, messageType, entityType, entityId, content } as an untyped object literal — no interface enforces field names or value types
  • src/scripts/card.js:8-11createCard reads cardInfo.title, .side_code, .faction_code, .type_code from an untyped parameter
  • src/scripts/deck.js:117-124cardElementToCardInfo reconstructs the card-info shape from DOM attributes — must match what createCard expects, but nothing enforces this
  • src/scripts/game.js:35 — Variable named cardIfo (typo for cardInfo) — a typed parameter would surface this during type checking

Arasaka Queue Planning Division.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions