Skip to content

Documentation

TypeScript SDK: Types, completion and diagnostics

Use async function run(ctx: Akmelo.Context): Promise<void> as the entry point. The platform supplies the context and invokes the function.

async function run(ctx: Akmelo.Context): Promise<void> {
  const response = await ctx.http().get(ctx.param<string>('catalog_url'));
  if (!response.ok()) ctx.fail(`HTTP ${response.status}`);
  const payload: unknown = response.json();
  if (!Array.isArray(payload)) ctx.fail('Expected a product array');
  for (const value of payload) {
    if (typeof value !== 'object' || value === null) continue;
    if (!('sku' in value) || typeof value.sku !== 'string') continue;
    ctx.emit({ sku: value.sku }, value.sku);
  }
}

ctx.param<T>(), ctx.params<T>(), ctx.json<T>() and response.json<T>() describe the expected shape. A generic does not validate data at runtime. Prefer unknown for external JSON, check arrays and required fields, then use the narrowed type.

Type Purpose
Akmelo.Context or Context Scenario parameters and services
Akmelo.Row Record<string, unknown>
Akmelo.Response, Akmelo.Dom, Akmelo.DomNode Website responses and HTML
Akmelo.Document, Akmelo.Worksheet, Akmelo.Cell Documents and cells
Akmelo.Price, Akmelo.Comparison Exact price comparisons

The editor highlights TypeScript, suggests SDK methods and displays server diagnostics by line after a typing pause. Outdated results never mark newer source. Saving rechecks source on the server independently of the browser.

TS2322 indicates incompatible types; TS2339 an unknown property or method; TS18046 unknown data that needs validation. Check a q() result for null or use optional chaining. Await asynchronous SDK methods.

A type assertion does not change data. Use Number or ctx.text().money(), check values and refine the shape instead of hiding an error. If the types are correct but the result is wrong, inspect the trial log.

Context · Documents