Skip to content

Operation

Operation = AddOperation | ReviseOperation | RetractOperation | RenameOperation

Commit operation accepted by client.commit.apply. Discriminated union over AddOperation, ReviseOperation, RetractOperation, and RenameOperation, keyed on operation.

Inline array literals passed directly to client.commit.apply are contextually typed by the parameter, so operation: "add" stays narrowed and the call typechecks. Binding the array to a variable without a type annotation widens operation to string, so the variable no longer assigns to the Operation[] parameter. Either annotate the variable as Operation[] (contextually typed by the annotation) or use satisfies Operation[] to preserve the inferred literal types:

// 1. Annotate the variable.
const ops: Operation[] = [
{ operation: "add", kind: "thing", name: "Sensor/temp-1", data: { x: 1 } },
{ operation: "revise", name: "Sensor/temp-1", data: { x: 2 } },
];
// 2. Or use `satisfies` to keep the inferred literal types.
const ops2 = [
{ operation: "add", kind: "thing", name: "Sensor/temp-1", data: { x: 1 } },
{ operation: "revise", name: "Sensor/temp-1", data: { x: 2 } },
] satisfies Operation[];
await client.commit.apply("acme", "world", "seed", ops);

https://docs.warmhub.ai/sdk/write-methods/#typing-operation-arrays