Skip to content

Using TypeScript

App-Compose comes with built-in TypeScript support, so you can start writing type-safe code right away.

When creating a Tag, you can specify the data type it holds.

import { createTag } from "@grlt-hub/app-compose"
const tag = createTag<string>({ name: "title" })

This provides full type safety for both Tag inputs and outputs.

Extracts the return type of a given Task.

import { type TaskResult, createTask } from "@grlt-hub/app-compose"
const alpha = createTask({
name: "alpha",
run: { fn: () => ({ value: "hello" }) },
})
type AlphaResult = TaskResult<typeof alpha> // => { value: string }

Represents the possible execution outcomes of a Task.

type TaskStatus = "done" | "fail" | "skip"

Represents a Task created by createTask. Use it to type function parameters or variables that hold a Task reference.

import { type Task, createTask } from "@grlt-hub/app-compose"
const alpha = createTask({
name: "alpha",
run: { fn: () => ({ value: "hello" }) },
})
// Use Task<T> to type a variable or function parameter that holds a Task reference
const ref: Task<{ value: string }> = alpha

Defines lifecycle hooks for observing stage and task execution.

import { type ComposeLogger } from "@grlt-hub/app-compose"
const myLogger: ComposeLogger = {
onTaskFail: (event) => console.log(event),
onStageStart: (event) => console.log(event),
onStageComplete: (event) => console.log(event),
}

Represents the configuration for a single stage passed to compose.

import { type StageConfig, createTask } from "@grlt-hub/app-compose"
const task = createTask({ name: "task", run: { fn: () => true } })
const stages: StageConfig = {
steps: [task],
}