Skip to content

Lint plugin

Action checks the shape of a tuple, not whether its path exists in your state (why). @input-actions/eslint-plugin fills that gap with one rule, input-actions/valid-paths, which uses the TypeScript type checker:

['action/save', ['draft', 'amont'], '1']
// ^^^^^^^ Path segment 'amont' does not exist on type '{ mode: …; amount: string; … }' (at draft)
['action/save', ['draft', 'amount'], 5]
// ^ Value of type '5' is not assignable to 'string' at path draft.amount
['action/toggle', ['draft', 'note']]
// ^^^^^^^^^^^^^^^^^ action/toggle targets 'string' at draft.note — expected a boolean

Requires ESLint 9 (flat config), TypeScript 5.4 or later, and @typescript-eslint/parser.

Terminal window
npm install -D @input-actions/eslint-plugin @typescript-eslint/parser eslint

Export your root state type by name, then point the rule at it:

eslint.config.mjs
import tsParser from '@typescript-eslint/parser';
import inputActions from '@input-actions/eslint-plugin';
export default [
{
files: ['src/**/*.{ts,tsx}'],
languageOptions: {
parser: tsParser,
parserOptions: {
projectService: true, // the rule needs type information
tsconfigRootDir: import.meta.dirname,
},
},
plugins: { 'input-actions': inputActions },
rules: {
'input-actions/valid-paths': [
'error',
{ stateType: 'AppState', typeFile: 'src/types.ts' },
],
},
},
];
Option
stateTypeName of the exported root state type or interface. Default AppState.
typeFileRequired. The file that exports it, relative to the project root. It’s matched against the end of each file’s path on whole segments, so lib/types.ts doesn’t match otherlib/types.ts.

If the type can’t be found, the rule reports stateTypeNotFound once per file, rather than passing silently.

Tuple literals anywhere in a file, including those nested in onSuccess, onError, onEnter and onExit lists. Calls to core’s helpers are checked too (save, toggle, increment, decrement, push, remove, del, merge, reset) when they’re imported by name from @input-actions/core.

ActionCheck
Every path actionEach path segment exists on the type.
saveThe value is assignable to the type at the path.
push, removeThe item is assignable to the array’s element type.
mergeEach key exists on the target, and its value is assignable.
toggleThe target is a boolean.
increment, decrementThe target is a number.
delete, resetThe path exists.

How path segments are checked:

  • A literal segment ('draft') must be a property of the current type, or the type must have an index signature (Record<string, T>, arrays).
  • A variable whose type is a union of string literals (a FeedTab variable used on a Record<FeedTab, T>) is checked once for each literal.
  • Any other variable (string, number) needs an index signature on the current type.
  • An any or unknown type ends the check for the rest of the path.

The rule checks what it can see statically and skips the rest silently:

  • A path held in a variable (const p = ['a']; ['action/save', p, v]), or built with a spread.
  • Spread members and computed keys in a merge object.
  • event/… placeholders in a value slot. They’re resolved when the action runs.
  • Machine names and modes, and async handler names. See what TypeScript doesn’t check.
  • Helpers imported under a namespace (import * as IA), or from anywhere other than @input-actions/core.

Type-aware linting loads your TypeScript program once per run. On the RWA example a full run takes about a second, almost all of it loading the program, which any type-aware rule pays. The rule only walks the paths you wrote, so its own time doesn’t grow with the size of your state type (ADR 0024 has the numbers).

Run it in CI and before commits. It works in the editor through the ESLint extension too.