Skip to main content
New aislop v0.9.4: four new Python rules from the SlopCodeBench paper, plus a CLI star prompt and GitHub Discussions. Read more →
ai-slop/unsafe-type-assertion manual fix

Unsafe type assertion.

An `as any` cast — bypasses TypeScript's checker entirely. Every guarantee from the type system is gone for that value forward.

Bad — what an agent ships
const user = res.data as any
user.profile.preferences.theme = 'dark' // any deep access, no checks
Good — what aislop hands back
// Validate at the boundary, then trust the type:
const user = UserSchema.parse(res.data)
user.profile.preferences.theme = 'dark' // typed all the way down

Agents reach for `as any` when they can't easily derive the real shape. It silences the error in 5 seconds and quietly disables the feature you bought TypeScript for.

How this rule is justified.

Rule id

ai-slop/unsafe-type-assertion

Enforcing engine

ai-slop

Detector strategy

Deterministic AST match: flags assertion expressions whose target type is `any`.

Legitimate code that is NOT flagged

Casts to a concrete type, validated parser output, and narrowing via type guards are not flagged.

Evidence

Unsafe type escapes appeared across unrelated projects in the first public scan batch.