TypeScript Type Safety
Detects type-system escape hatches: @ts-nocheck, @ts-ignore, @ts-expect-error, any usage, double assertions, implicit any catch clauses.
TypeScript provides several escape hatches for cases where the type system can't reason about runtime behavior: any, double assertions (as unknown as T), @ts-ignore, @ts-expect-error, and @ts-nocheck. Each one is sometimes necessary but bypasses the safety net. This analysis surfaces every escape-hatch use so they can be reviewed and replaced with narrower types when possible.
The score is 100 minus the deductions those escape hatches carry. Adoption of safe patterns (unknown, narrowing, satisfies, readonly, branded and Result types) is reported and never added back: a readonly field elsewhere in the file does not make an any safer.
Each construct is counted where the compiler honours it. A suppression directive counts at the start of a // comment or of the last line of a block comment, and @ts-nocheck only before the first statement; a comment that merely mentions a directive suppresses nothing and is not counted. x as unknown as T, with or without parentheses or in the angle-bracket form, is one double assertion. The exception is an evident widening: an object literal, or a const in the same file initialised with one, asserted through unknown to object, {}, Record<string, unknown> or another type that claims only "an object whose members must be narrowed". That claim is true by construction, so, like a lone x as unknown, it is not counted. Whether an unannotated catch variable is any depends on the tsconfig that owns the file, so that finding is made only where that tsconfig is known to compile without useUnknownInCatchVariables.
Severity guide
- info
- A positive type-safety pattern is in use, or a low-severity escape hatch (@ts-expect-error, an implicit `any` catch variable) is present.
- warning
- A type-safety escape hatch (`any`, a double assertion, @ts-ignore) is present; verify it is necessary and consider tightening.
- critical
- Type checking is disabled for the whole file (@ts-nocheck). This is high risk.
Remediation
Replace any with specific types or generics; remove @ts-nocheck; replace double assertions with proper type guards.
Replace any with specific types or generics; remove @ts-nocheck; replace double assertions with proper type guards.