Skip to main content
New aislop v0.13.1 patch — calibrates hidden-fallback detection and fixes regex comment-masker false positives. Read the changelog →
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.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

Flagged example
const user = res.data as any
user.profile.preferences.theme = 'dark' // any deep access, no checks
Why this trips

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

Clean example
const user = UserSchema.parse(res.data)
user.profile.preferences.theme = 'dark'
What changed

Validate untrusted data at the boundary and carry the narrowed type forward. If the shape is internal, model it with an interface or type guard instead of erasing it with `any`.

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.