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 booleanInstall
Section titled “Install”Requires ESLint 9 (flat config), TypeScript 5.4 or later, and @typescript-eslint/parser.
npm install -D @input-actions/eslint-plugin @typescript-eslint/parser eslintConfigure
Section titled “Configure”Export your root state type by name, then point the rule at it:
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 | |
|---|---|
stateType | Name of the exported root state type or interface. Default AppState. |
typeFile | Required. 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.
What’s checked
Section titled “What’s checked”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.
| Action | Check |
|---|---|
| Every path action | Each path segment exists on the type. |
save | The value is assignable to the type at the path. |
push, remove | The item is assignable to the array’s element type. |
merge | Each key exists on the target, and its value is assignable. |
toggle | The target is a boolean. |
increment, decrement | The target is a number. |
delete, reset | The 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
FeedTabvariable used on aRecord<FeedTab, T>) is checked once for each literal. - Any other variable (
string,number) needs an index signature on the current type. - An
anyorunknowntype ends the check for the rest of the path.
Not checked
Section titled “Not checked”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
mergeobject. 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.