# Typelock: type safety that stays switched on

> Replaces `as any` with type guards, schema parses, satisfies and unknown. Audits a folder for unsafe casts and fixes them in order of risk until tsc passes.

Typelock: type safety that stays switched on is a free AI agent skill on Agensi by MAJI, in Code Quality & Review. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [MAJI](https://www.agensi.io/creators/maji)
- Category: [Code Quality & Review](https://www.agensi.io/skills/code-quality-review)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-18
- Security: scan passed (2026-10-18); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/typelock-type-safety-that-stays-switched-on
- Tags: code-review, typescript, type-safety, zod

## About this skill

A single `as any` cast can silence errors across an entire call chain, hiding bugs that only appear at runtime. This skill enforces TypeScript type safety by replacing unsafe casts and non-null assertions with verifiable compiler checks.

### What it does
- **Eliminates `any` casts** by swapping them for type guards, `satisfies` operators, or exhaustive `never` checks.
- **Validates data boundaries** using the project's existing schema libraries like Zod or Valibot to parse external inputs.
- **Audits codebases** to find and rank type-safety risks in files or folders, prioritizing API boundaries and shared utilities.
- **Refactors unsafe patterns** such as non-null assertions and `@ts-ignore` comments into safer alternatives like narrowing or `@ts-expect-error`.
- **Recommends strict configurations** one flag at a time, such as like `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes`.

### How it works
1. **Context discovery**: The skill analyzes the project's stack, `package.json`, and `tsconfig.json` to identify existing validation libraries and strictness levels.
2. **Audit execution**: Run `audit <path>` to generate a prioritized list of type-safety violations ranked by risk level.
3. **Refactor and verify**: The skill applies fixes in batches, running `tsc --noEmit` after each change to ensure no new errors are introduced.

### Frameworks & tools
Works with any TypeScript project. It integrates with validation libraries like Zod and Valibot, and utilizes standard TypeScript features like `satisfies`, `unknown`, and type predicates.

### Why this beats prompting it yourself
Generic prompts often replace `as any` with `as unknown as T`, which just moves the problem. This skill follows a specific hierarchy of safety, forcing runtime validation at boundaries and narrowing within local logic to ensure types actually match reality.

### Use cases
- Refactoring a legacy TypeScript codebase to enable strict mode.
- Sanitizing API responses and environment variables to prevent runtime crashes.
- Removing non-null assertions from complex logic chains to handle edge cases safely.
- Implementing exhaustive switch-case checks to prevent bugs when adding new union members.

### Known limitations
Does not add new heavy dependencies for validation. Casts that are truly unavoidable in third-party glue code are wrapped rather than fully eliminated.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Typelock: type safety that stays switched on skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does 'Typelock' differ from just running the TypeScript compiler?

This skill identifies and replaces unsafe patterns like 'as any', non-null assertions, and '@ts-ignore' with safer alternatives like type guards and Zod schemas, ensuring your TypeScript types actually reflect runtime reality.

### Which AI agents or IDEs can I use this skill with?

The skill is compatible with any AI agent that has file-system access and a TypeScript environment, allowing it to run audits and verify fixes using your project's local 'tsc' installation.

### Does this skill require me to install new heavy dependencies or libraries?

No, the skill is designed to work with your project's existing stack; if you use Zod or Valibot, it will leverage them, otherwise it utilizes native TypeScript features like 'satisfies' and type predicates to avoid adding overhead.

### How does the skill ensure that automated refactoring doesn't break my existing code?

The skill follows a 'verify-after-fix' protocol, where it runs 'tsc --noEmit' after every refactor batch to ensure that the changes haven't introduced new type errors or broken the build.

### What exactly is included in this free skill?

One SKILL.md: the replacement order for `as any`, the audit steps and report format, and the rules. It is free.

### Can I use this on a large legacy codebase without refactoring everything at once?

The 'audit' command scans your requested path and generates a risk-ranked report, highlighting API boundaries and shared utilities where unsafe types pose the greatest threat to your application's stability.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
