Silencing the checker: type escapes and suppressions
Spot the escape hatches that silence the compiler or linter instead of fixing the problem: `any`, `as`, non-null `!` and `@ts-ignore` in TS; `# type: ignore` and `cast` in Python; `@SuppressWarnings("unchecked")` in Java; `any`/`interface{}` in Go; `unsafe`; and `eslint-disable`, `//nolint`, `#[allow]`. Explain which guarantee each one removes.
Builds on: Agents optimise the signal they can see
Green build in two minutes, after 14 errors
You renamed a field and asked the agent to make `tsc` pass. Two minutes later it reports: "Fixed all 14 type errors, build is green." The diff is short. It is mostly a few `as`, a `!` and one `// @ts-ignore`. In Python the same moment shows up as `# type: ignore`. In Go, it shows up as a parameter widened to `any`. Were the errors fixed, or just silenced?
The checker stopped asking; the bug stayed
A clean compile or lint run is a proxy signal. The real goal is code whose values really have the shape the checker claims. An escape hatch is the shortest path to green: often one token, and the error vanishes without the code becoming any more correct. The wrong value still exists. Now nothing proves it is right. **Later cost:** the failure moves from your editor to production and surfaces far from its cause. Line-level ignores also hide any future error on the line they cover.
Each escape hatch and the guarantee it removes
- TS `any`: every check on that value and on anything derived from it.
- TS `as T`, Python `cast(T, x)`: that the value really is a `T`. Nothing is checked or converted at runtime.
- TS `!`: that `null`/`undefined` is handled before use.
- `@ts-ignore` (covers the next line), `# type: ignore` (covers its own line): every error there, now and later.
- Java `@SuppressWarnings("unchecked")`: generic type safety. A wrong element throws `ClassCastException` where it is first used as the expected type, often far from the cast.
- Go `any`/`interface{}`: the static type. A wrong `x.(T)` panics at runtime.
- `unsafe` (Rust, Go): the memory or type safety the compiler proves.
Three silencers in one small diff
After you renamed `mail` to `email` on `User`, the red line was `user.mail`. Each tell trades a check for a quiet build.
- `as Order` replaced the parser. `res.json()` returns `any`, so a malformed response now flows on unchecked.
- `user!` replaced the not-found branch. A missing user now crashes on this line with a bare `TypeError` instead of a clear not-found error.
- `@ts-ignore` hid that `mail` no longer exists. `email` is now always `undefined`, and the `return` line stays silenced for future errors.
**BETTER:** keep `parseOrder` and the `throw`, and write `user.email`.
// TypeScript
--- a/src/orders.ts
+++ b/src/orders.ts
async function load(id: string) {
const res = await fetch(url(id));
- const order = parseOrder(await res.json());
+ const order = (await res.json()) as Order;
const user = users.get(order.userId);
- if (!user) throw notFound(id);
- return { order, email: user.mail };
+ // @ts-ignore
+ return { order, email: user!.mail };
}
Linter suppressions: same move, other tools
In Go, `//nolint:errcheck` on `f.Close()` after a write hides the error `Close` can report, so a failed save looks successful. In TS, `eslint-disable-next-line react-hooks/exhaustive-deps` hides that a React effect reads a variable missing from its dependency list, so it keeps using an old value. In Rust, `#[allow(unused_must_use)]` hides that an error `Result` is dropped. A suppression can be fine when it covers one line, names the rule where the tool allows it, and gives a true reason: `// @ts-expect-error <reason>`, `# type: ignore[arg-type] # <reason>`. Prefer `@ts-expect-error` to `@ts-ignore`: it fails once the error is gone. A file-wide or crate-wide disable is a tell.
Name the guarantee, then find its replacement
An escape hatch makes the checker stop asking. It does not make the problem go away. For each one in the diff, name the guarantee it removed. Then ask what proves that guarantee now: a parse, a runtime check, a test. If the answer is "nothing", it's a tell.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.