Skip to main content

Type Reference

The template includes full TypeScript type definitions for the Subway Builder Modding API v1.0.0. Here's how they're organized.

File Structure

Types are split across multiple .d.ts files in src/types/, grouped by API namespace:

FileWhat it covers
api.d.tsThe main ModdingAPI interface — ties everything together
index.d.tsRe-exports all types + declares window.SubwayBuilderAPI
core.d.tsPrimitives: Coordinate, BoundingBox, GameSpeed, BuildType, ElevationType
game-state.d.tsEntity types: Station, Track, Train, Route, DemandData, ridership types
game-constants.d.tsGameConstants, ConstructionCosts, HighSlopeSpeedMultiplier
game-actions.d.tsBond, BondType, BondResult
build.d.tsBuild automation: BlueprintTrackInput, PlaceBlueprintResult, CreateRouteOptions, etc.
ui.d.tsUI system: UIPlacement, button/toggle/slider/panel option types
cities.d.tsCity, CityConfig, CityTab, CityDataFiles, ViewState
trains.d.tsTrainTypeConfig, TrainTypeStats
stations.d.tsStationTypeConfig
map.d.tsMap types: MapSource, MapLayer, TileURLOverride, RoutingServiceOverride
career.d.tsMissionConfig, StarConfig, CareerMetrics, CareerOperators
content-templates.d.tsNewspaperTemplate, TweetTemplate
pop-timing.d.tsCommuteTimeRange
storage.d.tsMod storage: set, get, delete, and keys methods for persistent mod data storage
i18n.d.tsI18nAPI
utils.d.tsRechartsComponents
schemas.d.tsGameSchemas (Zod validation schemas)
electron.d.tsElectronAPI, ElectronAPIExtended
manifest.d.tsModManifest
warning

The build/storage API types are listed on the official API documentation but are currently unusable at runtime.

How It Works

index.d.ts re-exports everything and declares the global Window interface:

declare global {
interface Window {
SubwayBuilderAPI: ModdingAPI;
electron?: ElectronAPI;
electronAPI?: ElectronAPIExtended;
}
}

This gives you full autocomplete when you type window.SubwayBuilderAPI. in your editor.

Key Types at a Glance

Game Entities

interface Station {
id: string;
name: string;
coords: [number, number]; // [longitude, latitude]
trackIds: string[];
routeIds: string[];
nearbyStations: NearbyStation[];
buildType: string;
createdAt: number;
// ...
}

interface Track {
id: string;
coords: [number, number][]; // Start and end points
trackType: string; // 'heavy-metro', 'light-metro', etc.
startElevation: number;
endElevation: number;
length: number;
// ...
}

interface Route {
id: string;
bullet: string; // Display label ('A', '1', etc.)
color: string; // Hex color
stations: RouteStation[];
trainIds: string[];
// ...
}

interface Train {
id: string;
routeId: string;
position: Coordinate;
speed: number;
// ...
}

Core Primitives

type Coordinate = [number, number]; // [longitude, latitude]
type BoundingBox = [number, number, number, number]; // [minLng, minLat, maxLng, maxLat]
type GameSpeed = 'slow' | 'normal' | 'fast' | 'ultrafast';
type BuildType = 'blueprint' | 'built';

UI Types

type UIPlacement =
| 'settings-menu'
| 'escape-menu'
| 'escape-menu-buttons'
| 'main-menu'
| 'bottom-bar'
| 'top-bar'
| 'debug-panel'
| 'menu-items'
| 'pause-menu'
| 'debug';

type NotificationType = 'success' | 'error' | 'info' | 'warning';

Extending Types

If you need to extend the API types (e.g., adding fields you've discovered at runtime), you can use TypeScript declaration merging in your own .d.ts file:

// src/types/my-extensions.d.ts
declare module './game-state' {
interface Station {
myCustomField?: string;
}
}

Official Documentation

For the most up-to-date API reference, see the official Subway Builder modding docs.