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/double-type-assertion manual fix

Double type assertion.

An `as unknown as X` cast — a double-cast escape hatch used when the compiler refuses a direct `as X`. Smuggles types through without validation.

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
type User = {
  id: string
  email: string
  plan: 'free' | 'pro'
}

const user = response.body as unknown as User
sendWelcomeEmail(user.email)
Why this trips

Deterministic AST match: flags chained assertions of the form `as unknown as T`.

Clean example
const user = UserSchema.parse(response.body)
sendWelcomeEmail(user.email)
What changed

Replace the double assertion with runtime validation, a parser, or a type guard. If you really need an assertion, assert once to a concrete type and document why the compiler cannot know it.

When TS rejects a single cast with "Type X is not assignable to Y", agents reach for the double cast as the next escape hatch. Same problem, more hidden.

How this rule is justified.

Rule id

ai-slop/double-type-assertion

Enforcing engine

ai-slop

Detector strategy

Deterministic AST match: flags chained assertions of the form `as unknown as T`.

Legitimate code that is NOT flagged

A single deliberate assertion with a reason, or runtime validation that produces the target type, is not flagged.

Evidence

Provenance: repeated across public scans as the follow-on escape hatch once a direct cast is rejected.