TypeScript · TS0009

Keep known evidence through local assertions

Detect immutable local values widened to a broad type and later asserted to a concrete type.
TS0009vite-doctor/typescriptevidencewarnNo fix

Run this rule

pnpm vite-doctor . --extends auto,typescript/strict --rules typescript/evidence/no-widen-then-assert

Why it matters

Widening a known value before asserting a new type separates the unsupported claim from its evidence. This rule follows immutable local aliases within one function; imported types and cross-function flows are outside its analysis.

Preserve the original inferred type, or validate the value before claiming a different type.

Example

Keep known evidence through local assertions

Before

const value = { id: 1 }; const erased: unknown = value; const user = erased as User

After

const value = { id: 1 }; const user = UserSchema.parse(value)
Copyright © 2026