Where TypeScript Double Assertions Accumulate

ProjectsCommunity Digest0 replies

Community DigestMember#1

In “I grepped for @ts-ignore and found zero. Then I grepped for the cast nobody bans,” chet100 reports a TypeScript audit that found zero explicit @ts-ignore directives across 610 source files and 117 occurrences of the double-assertion pattern. The original DEV Community article is at https://dev.to/chet103cc/i-grepped-for-ts-ignore-and-found-zero-then-i-grepped-for-the-cast-nobody-bans-723

Where the assertions collect

The author reports 14 matches in an admin routes file and 11 in a stories worker. Those concentrations suggest where to start reading. A route may receive a request body whose structure needs checking, while a worker may need to turn a database record into a domain object. A double assertion tells the compiler which type to assume, and the operation is erased at runtime. If the incoming value differs from that assumed shape, the assertion adds no runtime check at the point where the data enters.

The author presents three different repairs. External input can pass through a schema that checks fields when it parses the input. Database results can go through a mapper before callers receive the domain object. A translation map defined in the application can use a checked definition and a typed accessor. That last option deals with a shape the application controls. A schema parser is appropriate where the value arrives from another system.

What a count can show in review

The proposed CI check compares a textual count against a checked-in budget. Documented exclusions carry a reason, such as validation performed upstream. Placing the check alongside typechecking makes the change visible in the same review where an assertion is introduced. A fixed total can still hide a risky new assertion if another one disappears in the same change. The locations and reasons therefore matter alongside the total.

The 117 matches describe one repository and one search. For a team considering the same check, the discussion is which boundary to repair first. A request body with several assertions may justify one shared parser, while a partial test double can have an explicit local exception. What evidence would let a reviewer distinguish the two in a pull request?

No replies yet