deslop/unnecessary-assertion
Flag TypeScript assertions that are no-ops or weaken types (`x!!`, `as any`, `as unknown as T`, `<T>x`).
- Category: Correctness
- Severity: warn
- Source:
deslop-js - Framework: global
- Enabled when: react-doctor deadCode analysis enabled (default true); whole-project scan only — skipped in --diff/--staged modes
- Documentation: https://github.com/millionco/deslop-js
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Fires from deslop's unnecessaryAssertions detector with one of five kinds: double-non-null on x!! ("the second ! is always a no-op"), redundant-non-null-on-literal when ! trails a literal/array/object/function expression ("those values are never null"), redundant-double-assertion when an outer as T wraps an inner as any/as unknown ("x as any/unknown as T first widens just to assert to T"), assertion-to-any on any as any ("opts out of TypeScript's type system"), and angle-bracket-assertion on <T>x syntax ("parsed as a JSX tag in .tsx and deprecated"). The double-non-null, redundant-non-null-on-literal, and redundant-double-assertion kinds are high confidence; assertion-to-any and angle-bracket-assertion are medium. False positive to SUPPRESS: assertion-to-any on a deliberate, commented escape hatch where no concrete type exists, and redundant-double-assertion on a genuine x as unknown as T bridge between two structurally unrelated types where the inner unknown is the only legal way to force the cast — judge by whether the intermediate any/unknown is truly removable without a compile error, not just present.
Fix prompt
Use this once validation confirms the diagnostic is real.
For double-non-null drop one ! (x!! becomes x!); for redundant-non-null-on-literal remove the trailing ! since the value is never null; for redundant-double-assertion drop the intermediate cast and assert once (x as any as T becomes x as T), keeping as unknown as T only when the direct cast genuinely will not compile; for assertion-to-any replace as any with the real type or narrow with unknown plus a guard (if (typeof v === "string")) instead of opting out of type checking; for angle-bracket-assertion rewrite <T>x as x as T so it does not parse as JSX. See https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions