Skip to main content

createCommand()

function createCommand<T>(
type: T,
args: SyncCommandsMap[T],
tempId?: string): SyncCommand<T>;

Creates a strongly-typed Sync API command with an auto-generated UUID.

Type Parameters

Type Parameter
T extends keyof SyncCommandsMap

Parameters

ParameterTypeDescription
typeTThe command type (e.g. 'item_add', 'project_update').
argsSyncCommandsMap[T]The command arguments, constrained by the command type.
tempId?stringOptional temporary ID for referencing the created resource in subsequent commands.

Returns

SyncCommand<T>

A fully formed SyncCommand ready to include in a sync request.

Example

const cmd = createCommand('item_add', { content: 'Buy milk', priority: 2 })
// cmd.type === 'item_add'
// cmd.args is typed as TaskAddArgs