Generated Types
The TypeScript types ocpp-ws-io generates from the official OCPP 1.6, 2.0.1 and 2.1 JSON schemas, and how a call or handler finds its types.
ocpp-ws-io ships TypeScript types for every OCPP 1.6, 2.0.1 and 2.1 action, generated from the official OCA JSON schemas. You do not generate anything for the standard versions: the types are in the package. To use them in your code, see the TypeScript Guide.
What's included
Every action has a typed request and response, and every OCPP 2.1 unconfirmed (SEND) message a typed payload:
- OCPP 1.6:
Authorize,BootNotification,Heartbeat,MeterValues,StartTransaction,StopTransaction,Resetand all others, with the security extension (SignedFirmwareStatusNotification,SecurityEventNotification, …) - OCPP 2.0.1:
BootNotification,TransactionEvent,StatusNotification,RequestStartTransactionand all others - OCPP 2.1: every action and SEND message of the OCA schemas (typed from the schemas; not yet tested against real 2.1 hardware)
The types follow the schemas exactly: a required field is required, an enum is a union of its values, and a key a schema does not define is a type error. An object a schema leaves open (OCPP 2.0.1 and 2.1 customData) takes any JSON.
How a call finds its types
protocols ──▶ P ──▶ OCPPMethodMap[P] ──▶ action ──▶ request / response
└─▶ OCPPSendMethodMap[P] ──▶ SEND message ──▶ payload- The
protocolsyou configure become the type parameterP:new OCPPClient({ protocols: ["ocpp1.6"] })is anOCPPClient<"ocpp1.6">. Pselects its method map inOCPPMethodMap("ocpp1.6"→OCPP16Methods), and its SEND messages inOCPPSendMethodMap.- The action name selects the request and the response from that map, for the params of
call()and theparamsand return value ofhandle().
All of this happens at compile time; nothing of it exists at runtime. OCPPMethodMap and OCPPSendMethodMap are interfaces, so you can add your own protocols and actions to them: see vendor actions and custom protocols.
Reading the generated types
import type {
AllMethodNames,
OCPP16Methods,
OCPPRequestType,
OCPPResponseType,
} from "ocpp-ws-io";
// All action names of OCPP 1.6
type Methods16 = AllMethodNames<"ocpp1.6">;
// "Authorize" | "BootNotification" | "ChangeAvailability" | ...
// The request and response of BootNotification
type BootRequest = OCPPRequestType<"ocpp1.6", "BootNotification">;
// { chargePointVendor: string; chargePointModel: string; ... }
type BootResponse = OCPPResponseType<"ocpp1.6", "BootNotification">;
// { currentTime: string; interval: number; status: "Accepted" | "Pending" | "Rejected" }
// The same, straight from the method map
type SameRequest = OCPP16Methods["BootNotification"]["request"];The TypeScript Guide lists every type utility.
Types for your own schemas
For a custom protocol with JSON schemas, ocpp generate (the CLI in ocpp-ws-io) writes the same kind of types, the declaration that adds the protocol to OCPPMethodMap, and a validator, all from your schemas: see Project Setup & Generation. It uses the same generator as the library's own types below.
For Contributors: Re-generating Types
If you are contributing to ocpp-ws-io and need to regenerate types from updated JSON schemas:
npm run generateThis reads schemas from src/core/validation/schemas and outputs to src/generated/. You should not need to do this unless you are modifying the OCPP schemas themselves.