TypeScript · strict
TS0008Explain necessary type assertions
Require a nearby SAFETY comment for non-const TypeScript assertions, except Vue's `X as PropType<T>` prop declarations.
vite-doctor/typescriptstrictwarnSuggestion
Why it happens
A necessary assertion depends on an invariant TypeScript cannot express. Recording that invariant lets reviewers verify the claim and detect when later changes invalidate it.
Fix
Remove the assertion, or add a specific SAFETY comment immediately before the containing statement, or before the line of the ternary, &&, ||, or else branch that holds it.
Example
State the checked invariant
Before
const userId = value as UserId
After
// SAFETY: parseUserId validated the identifier before branding it.
const userId = value as UserId
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm vite-doctor . --extends auto,typescript/strict --rules typescript/strict/require-safety-comment-for-type-assertion