Fix type assertions and improve TypeScript type safety. Use when encountering 'as unknown as' casts, manual type definitions that duplicate schema types, or unclear type errors in database queries, especially with Drizzle ORM relations. Also use when verifying types
التثبيت
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Fix type assertions and improve TypeScript type safety. Use when encountering 'as unknown as' casts, manual type definitions that duplicate schema types, or unclear type errors in database queries, especially with Drizzle ORM relations. Also use when verifying types
triggers
["Property 'workout' does not exist","Property 'track' does not exist","Property 'competition' does not exist","Property 'organizingTeam' does not exist","TS2339: Property does not exist on type","TS2551: Property does not exist","with: { relation: true }","as unknown as","Drizzle relation type"]
Type Safety
Improve TypeScript type safety by eliminating unsafe type assertions and using proper types from the source.
CRITICAL: Drizzle Relation Type Inference Failure
This is a recurring bug in WODsmith. Drizzle's with: { relation: true } clause does NOT automatically include relation types in the return type. This causes:
error TS2339: Property 'workout' does not exist on type '{ id: string; trackId: string; ... }'
error TS2551: Property 'track' does not exist on type '{ ... }'. Did you mean 'trackId'?
Strategy 2: Explicit Join (Most Type-Safe, for complex queries)
When relation chains are deep or you need specific fields:
// Instead of .with() which has type inference issues:const result = await db
.select({
id: trackWorkoutsTable.id,
trackId: trackWorkoutsTable.trackId,
// ... other trackWorkout fieldsworkout: workoutsTable, // Full workout object// OR select specific fields:workoutName: workoutsTable.name,
workoutScheme: workoutsTable.scheme,
})
.from(trackWorkoutsTable)
.innerJoin(workoutsTable, eq(trackWorkoutsTable.workoutId, workoutsTable.id))
.where(eq(trackWorkoutsTable.id, id))
Strategy 3: Type Guard for Optional Relations
// When relation might not be loadedif (result && 'workout'in result && result.workout) {
const workout = result.workoutasWorkout// Use workout safely
}
// Or with type guard functionfunctionhasWorkout(tw: TrackWorkout): tw is TrackWorkout & { workout: Workout } {
return'workout'in tw && tw.workout !== undefined
}
Common WODsmith Type Error Patterns
Pattern 1: Missing .workout on trackWorkout
Error:Property 'workout' does not exist on type '{ createdAt: Date; ... workoutId: string; }'