Essential AI Coding Feedback Loops For TypeScript Projects
When working with AI coding agents, especially those operating independently, you need feedback loops so the AI can verify its own work. Feedback loops are especially important when you're doing AFK coding, such as with Ralph Wiggum.
1. Set Up TypeScript and Type Checking
TypeScript is essentially free feedback for your AI. Use it over JavaScript.
Create a typecheck script in your package.json:
{"scripts": {"typecheck": "tsc"}}
TypeScript catches errors the AI would never find without testing in a browser.
2. Add Automated Tests
Use a test framework like Vitest for logical errors:
{"scripts": {"test": "vitest"}}
Basic unit tests covering core functionality help keep the AI on track.
3. Install Husky for Pre-commit Hooks
Husky enforces feedback loops before every commit.
Install and initialize Husky:
pnpm install --save-dev huskypnpm exec husky init
Create a .husky/pre-commit file that runs all your checks:
npx lint-stagednpm run typechecknpm run test
If any step fails, the commit is blocked and the AI gets an error message.
Another powerful feedback loop is making sure the LLM can access your running dev server locally to check your frontend. See this video for how to set that up.
4. Set Up Automatic Code Formatting
Use lint-staged with Prettier to auto-format code before commits.
Install lint-staged:
pnpm install --save-dev lint-staged
Configure .lintstagedrc:
{"*": "prettier --ignore-unknown --write"}
This runs Prettier on all staged files and automatically restages them. All AI-generated code now conforms to your formatting standards.
We could also run ESLint here since it works nicely with lint-staged.
Why This Works for AI
AI agents don't get frustrated by repetition. When code fails type checking or tests, the agent simply tries again. This makes feedback loops (and pre-commit hooks, especially) incredibly powerful for AI-driven development.