TypeScript · TS0001
Do not chain type assertions
Reject nested TypeScript assertions that manufacture type evidence, unless a SAFETY comment states the invariant.
typescript/evidence/no-chained-type-assertionssrc/rule-packs/typescript/rules/no-chained-type-assertions.ts Upstream docs Run this rule
pnpm vite-doctor . --rules typescript/evidence/no-chained-type-assertions
Why it matters
Each assertion asks the compiler to trust the author. Chaining assertions can erase the original type before claiming an unrelated result type, so neither the compiler nor a reviewer can verify the conversion.
Recommended fix
Keep the original precise type, narrow it with a type guard, or parse untrusted input into the target type. When the chain is necessary, state the invariant in a SAFETY comment immediately before the statement.
Useful links
Example
Parse before narrowing
Before
const user = input as object as User
After
const user = UserSchema.parse(input)
Document a necessary chain
Before
const driver = db as unknown as SqlDriver
After
// SAFETY: every supported Drizzle SQLite database has the run and all methods of SqlDriver.
const driver = db as unknown as SqlDriver