> ## Documentation Index
> Fetch the complete documentation index at: https://acme-c84a37e5.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript

> Tipos genéricos, helpers y reglas con inferencia de tipos

## Genéricos en `run`

```typescript theme={null}
import { run } from "runtry";

type Item = { id: string };
const r = await run<Item>(() => fetch("/api").then((x) => x.json()));
```

## Helpers de resultado en `runAll`

```typescript theme={null}
import { runAll, isSuccess, type SuccessResult, type ErrorResult } from "runtry";

const rs = await runAll<number>([async () => 1]);
const ok: SuccessResult<number>[] = rs.filter(isSuccess);
const ko: ErrorResult<any>[] = rs.filter((r) => r.status === "error");
```

## Reglas y tipos

```typescript theme={null}
import { createRunner, errorRule } from "runtry";

type MyError = { code: "HTTP"; message: string; status?: number };

const runner = createRunner({
  rules: [
    errorRule.when((e): e is { status: number } => typeof (e as any)?.status === "number").toError<MyError>((e) => ({
      code: "HTTP",
      message: "failed",
      status: (e as any).status,
    })),
  ],
});
```
