type-safety

Eliminate unsafe TypeScript type assertions in Drizzle ORM queries.

2|2|Updated May 30, 2025
One-click install
npx skills add https://github.com/wodsmith/thewodapp --skill type-safety-wodsmith
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-safety
Source: https://github.com/wodsmith/thewodapp/tree/main/.claude/skills/type-safety
Command: npx skills add https://github.com/wodsmith/thewodapp --skill type-safety-wodsmith

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Eliminates unsafe type assertions and improves TypeScript type safety, with a focus on Drizzle ORM relation inferences and common TS errors like TS2339/TS2551.

Core Features & Use Cases

  • Strategy 1: Type alias with intersection to include related data.
  • Strategy 2: Explicit joins for complex relations.
  • Strategy 3: Type guards for optional relations.
  • Patterns: Regular patterns for missing properties, new schema fields, and safe casting.

Quick Start

Apply the patterns shown to resolve errors like “Property 'workout' does not exist on type” by creating a TrackWorkoutWithWorkout type or by switching to explicit joins as appropriate.

Frequently Asked Questions about type-safety

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

FAQPage Schema
How do I fix TypeScript errors when accessing relation properties in Drizzle ORM queries?

Type-safety eliminates unsafe type assertions in Drizzle ORM by applying Type Alias Cast, Explicit Joins, or Type Guards. Create intersection types like `TrackWorkoutWithWorkout` to guarantee accurate return types and safe access to nested relation properties, resolving errors like TS2339.

What's the best way to handle unsafe type casts with multi-relation queries in Drizzle?

Use explicit joins or type alias intersections instead of unsafe casts. This approach ensures TypeScript recognizes all relation properties upfront, preventing runtime errors and improving type inference across complex nested relations and schema changes.

When should I use type guards versus type aliases for optional relations in TypeScript?

Type guards validate optional relations at runtime and narrow types safely. Type aliases with intersections work best for guaranteed relations. Choose type guards when relation presence is conditional; use type aliases when relations are always populated in your query result.

Can I apply type-safety patterns when my database schema adds new columns to existing tables?

Yes. Type-safety patterns handle schema evolution by explicitly defining relation types and using type aliases to reflect new columns. This prevents property-does-not-exist errors when schema changes introduce fields Drizzle's inference hasn't yet recognized.

How do explicit joins improve type safety compared to implicit relation inference in Drizzle?

Explicit joins give TypeScript full visibility into which relations are fetched, enabling precise type inference without unsafe assertions. This eliminates gaps in type coverage that implicit inference creates, especially with nested or multi-table relations.