Harden TypeScript types

Use Autohand Code with TypeScript skill guidance to reduce unsafe casts, add type guards, and make important contracts visible to the compiler.

Replace weak types with useful compile-time checks

TypeScript Build and change Implementation Code

autohand -p "Harden the types in this module without changing runtime behavior"

Safer TypeScript contracts, fewer assertions, and passing type or test checks.

Harden TypeScript types with Autohand Code is a type-safety workflow that uses TypeScript refactoring patterns to replace weak contracts with narrower types, guards, generics, and readable compiler-enforced boundaries. ### At a glance | Question | Answer | | --- | --- | | Best for | modules with broad any usage, unsafe casts, unclear API shapes, or fragile runtime checks | | Primary inputs | Target files or package; Current typecheck command and failing compiler output; Runtime behavior that must stay stable | | Autohand Code returns | Safer TypeScript contracts, fewer assertions, and passing type or test checks. | | Avoid when | the public contract is still changing or a runtime behavior change is the real goal | ### How Autohand Code handles this workflow 1. Finds unsafe casts, loose inputs, and hidden data shapes. 2. Chooses type guards, discriminated unions, generics, or branded types where they clarify real behavior. 3. Keeps runtime code stable unless a guard is needed at an external boundary. 4. Runs typecheck and focused tests, then lists any remaining intentional gaps. ### Best inputs - Target files or package - Current typecheck command and failing compiler output - Runtime behavior that must stay stable ### Strong prompt autohand -p "Harden the types in this module without changing runtime behavior" ### Autohand Code CLI options - Use `/skills use typescript-refactoring-patterns` before the change when the skill is installed. - Run `autohand -p "Harden the types in this module without changing runtime behavior"` with the typecheck command. - Use `--patch` when reviewers want to inspect the proposed type changes before applying them. ### Review before accepting Review the diff for fewer unsafe assertions, clearer exported types, passing typecheck, and unchanged runtime tests. ### Source and validation signals Autohand AI maintains this workflow as first-party product guidance for Autohand Code. Use the [Autohand CLI Playbook](https://github.com/autohandai/code-cli/blob/main/docs/AUTOHAND_PLAYBOOK.md), [CLI reference](/docs/working-with-autohand-code/cli-reference.html), and [configuration reference](https://github.com/autohandai/code-cli/blob/main/docs/config-reference.md) when choosing between interactive mode, command mode, auto-mode, feature-enabled /goal, /settings, skills, MCP, and permission settings. The related resources below link to product docs and tutorials for the workflow, and the final answer should name repository-specific files, commands, outputs, or docs that a reviewer can verify. ### Frequently asked questions ### What is Harden TypeScript types with Autohand Code? Harden TypeScript types with Autohand Code is a type-safety workflow that uses TypeScript refactoring patterns to replace weak contracts with narrower types, guards, generics, and readable compiler-enforced boundaries. ### When should a team use Harden TypeScript types? Use it before refactoring shared TypeScript code whose current types do not protect callers. ### What evidence should reviewers check for Harden TypeScript types? Review the diff for fewer unsafe assertions, clearer exported types, passing typecheck, and unchanged runtime tests.

Skill Skilled: TypeScript Refactoring Patterns Use the TypeScript refactoring skill as the source pattern. https://skilled.autohand.ai/skill/typescript-refactoring-patterns Reference Agent Skills Load and invoke skills inside Autohand Code. /docs/working-with-autohand-code/agent-skills.html Guide Code Refactoring Keep behavior stable while improving code shape. /docs/guides/code-refactoring.html