Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/aurelienbobenrieth/gadget/llms.txt

Use this file to discover all available pages before exploring further.

This rule requires that run and onSuccess exports use the generated ActionRun and ActionOnSuccess types from gadget-server. These types are auto-generated based on your action’s configuration and provide accurate type checking for parameters and context.

Rule Details

This rule checks that:
  • run exports are typed as ActionRun
  • onSuccess exports are typed as ActionOnSuccess
  • Manual type annotations are replaced with generated types
  • Missing type annotations are added
Severity: Error Auto-fixable: Yes

Examples

Incorrect

// Missing type annotation
export const run = async ({ params, record }) => {
  await save(record);
};

// Manual inline type
export const run: (params: any) => Promise<void> = async (params) => {};

// Wrong type name
export const onSuccess: () => Promise<void> = async () => {
  console.log("done");
};

// Missing onSuccess type
export const onSuccess = async () => {
  console.log("done");
};

Correct

// Proper ActionRun type
import { ActionRun } from "gadget-server";

export const run: ActionRun = async ({ params, record }) => {
  await save(record);
};

// Proper ActionOnSuccess type
import { ActionOnSuccess } from "gadget-server";

export const onSuccess: ActionOnSuccess = async ({ record }) => {
  await doSomething(record);
};

// Both correctly typed
import { ActionRun, ActionOnSuccess } from "gadget-server";

export const run: ActionRun = async ({ params }) => {};
export const onSuccess: ActionOnSuccess = async () => {};

// JSDoc type annotation also works
/** @type { ActionRun } */
export const run = async ({ params, record }) => {
  await save(record);
};

Auto-fixes

The rule automatically:
  1. Adds the type annotation if missing
  2. Replaces manual types with generated types
  3. Adds imports to gadget-server if needed
// Before
export const run = async ({ params }) => {};

// After auto-fix (no existing import)
import { ActionRun } from "gadget-server";
export const run: ActionRun = async ({ params }) => {};
// Before
import { applyParams, save } from "gadget-server";
export const run = async ({ params, record }) => {
  await applyParams(record, params);
  await save(record);
};

// After auto-fix (adds to existing import)
import { applyParams, save, ActionRun } from "gadget-server";
export const run: ActionRun = async ({ params, record }) => {
  await applyParams(record, params);
  await save(record);
};

Why Use Generated Types

The ActionRun and ActionOnSuccess types are auto-generated by Gadget based on:
  • Your action’s params definition
  • Whether it’s a model or global action
  • The model’s fields (for model actions)
  • Your action’s options
These types provide:
  • Accurate autocompletion for the context object
  • Type checking for parameters
  • Proper typing for record fields
  • Compile-time errors if you access undefined fields
Using the generated types gives you full type safety and autocompletion based on your specific action configuration.

When to Use

This rule is included in the recommended config and should always be enabled for Gadget projects. It ensures you get the full benefit of TypeScript type checking for your actions.

Build docs developers (and LLMs) love