Skip to content

@idlekitjs/types

Shared TypeScript contracts used across IdleKit packages. The package has no runtime logic.

What it provides

  • Extension, EngineContext and System.
  • EngineEvents, EventEmitter and EventHandler.
  • SaveAdapter, Migration and LoadResult.
  • Binding, StateKey and FlushListener.

When to use it

Most game code imports engine-level contracts from @idlekitjs/core, which re-exports them for convenience. Import from @idlekitjs/types when writing a package, renderer, adapter or integration that should depend on the contract without depending on the engine implementation.

Basic usage

ts
import type { Extension, SaveAdapter } from "@idlekitjs/types";

export function traceLoads<T extends object>(): Extension<T> {
  return {
    id: "trace-loads",
    setup(engine) {
      engine.events.on("loaded", () => {
        console.log("save loaded");
      });
    },
  };
}

export class SessionAdapter implements SaveAdapter {
  read(key: string) {
    return sessionStorage.getItem(key);
  }
  write(key: string, value: string) {
    sessionStorage.setItem(key, value);
  }
  remove(key: string) {
    sessionStorage.removeItem(key);
  }
}

Boundaries

@idlekitjs/types sits at the bottom of the dependency graph and imports no other IdleKit package. It only holds contracts shared across package boundaries. Mechanic-owned types such as RecipeDef, Project or ActiveBoost stay in their mechanic subpaths.