no-bare-casts

Identify and remediate unsafe TypeScript type assertions with type-safe alternatives.

47.5k|2.5k|Updated Jun 20, 2019
One-click install
npx skills add https://github.com/prisma/prisma --skill no-bare-casts
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: no-bare-casts
Source: https://github.com/prisma/prisma/tree/main/skills-contrib/no-bare-casts
Command: npx skills add https://github.com/prisma/prisma --skill no-bare-casts

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill addresses the technical debt and runtime risks associated with unsafe TypeScript type assertions, commonly known as bare casts. It provides a structured decision-making framework to replace dangerous type coercions with safer alternatives like runtime checks or explicit type declarations.

Core Features & Use Cases

  • Type Safety Enforcement: Guides developers through a decision tree to replace unsafe as casts with type predicates, satisfies, or explicit cast helpers.
  • Auditable Escape Hatches: Provides a standardized blindCast mechanism that requires a documented reason for any necessary type compromise.
  • Use Case: When refactoring legacy codebases, use this skill to systematically identify and replace unsafe type assertions with robust, type-safe patterns that satisfy the project's linting requirements.

Quick Start

Analyze the current file for any bare as casts and suggest the appropriate replacement based on the provided decision tree.

Frequently Asked Questions about no-bare-casts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I replace unsafe TypeScript type assertions in my codebase?

Replace bare TypeScript as casts by applying a structured decision tree that substitutes them with type predicates, satisfies operators, or explicit cast helpers to ensure runtime safety and type integrity.

What is a bare cast in TypeScript and why is it risky?

A bare cast in TypeScript is an unchecked type assertion using the as keyword. It is risky because it bypasses the compiler's type hierarchy, creating technical debt and potential runtime crashes if the actual data shape mismatches the asserted type.

How do I document necessary type compromises during TypeScript refactoring?

Document necessary type compromises during TypeScript refactoring by using a standardized blindCast mechanism, which provides an auditable escape hatch that requires a documented reason for bypassing strict type safety.

When should I use type predicates instead of as casts in TypeScript?

Use type predicates instead of as casts in TypeScript when you need to verify a variable's type at runtime before execution, ensuring the type compromise is explicitly declared, checked, and auditable rather than blindly asserted.

Does this approach to type safety work with existing static analysis workflows?

Yes, this type safety approach works with existing static analysis workflows by systematically identifying unsafe assertions and replacing them with robust, type-safe patterns that satisfy strict project linting requirements.