Skip to main content

SKY-T104 · Quality, structure and performance

TypeScript compiler suppression directive

Medium

@ts-ignore is reported MEDIUM, as the catalog says. A file-wide @ts-nocheck is reported HIGH.

// @ts-ignore tells the TypeScript compiler to hide every error on the next line, and // @ts-nocheck at the top of a file turns checking off for the whole file. SKY-T104 reports both. // @ts-expect-error is not reported, because the compiler complains once the error it expects is gone.

Languages
TypeScript, JavaScript
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A @ts-ignore added to silence one error also hides the next one on that line. Here it hides that a string is passed where the payment code expects a number of cents, so the charge goes out wrong and nothing warns about it.

What Skylos flags

src/checkout/pay.ts · TypeScriptReported on line 4
import { charge } from "./payments"; export async function checkout(cartId: string, amount: number) {  // @ts-ignore  return charge(cartId, amount.toFixed(2));}

What Skylos leaves alone

src/checkout/pay.ts · TypeScript
import { charge } from "./payments"; export async function checkout(cartId: string, amount: number) {  // @ts-expect-error charge() takes cents until payments v3 ships  return charge(cartId, amount.toFixed(2));}

Why Skylos leaves it alone

@ts-expect-error hides only an error that really exists, and the compiler fails the build once it no longer does. With a reason next to it, it is the reviewed way to accept a known type error.

More languages

JavaScript

Flagged

src/legacy/totals.js · JavaScriptReported on line 1
// @ts-nocheckexport function legacyTotal(items) {  return items.reduce((sum, item) => sum + item.price, 0);}

Not flagged

src/legacy/totals.js · JavaScript
// @ts-check/** @param {{ price: number }[]} items */export function legacyTotal(items) {  return items.reduce((sum, item) => sum + item.price, 0);}

Why Skylos leaves it alone

// @ts-check turns type checking on for a JavaScript file, the opposite of @ts-nocheck. Skylos reports only the pragma that turns it off.

How Skylos decides

  1. Runs with --quality on TypeScript and JavaScript files. Declaration files (.d.ts) and generated files (under build, dist, generated or vendor folders, *.gen.* or *.generated.* names, or with a generated-code header) are skipped.
  2. Reads the comments at the top of the file, before the first statement. When the last // @ts-check or // @ts-nocheck among them is @ts-nocheck, it reports that comment once, HIGH, and nothing else in the file.
  3. Otherwise it reports MEDIUM every // @ts-ignore comment (also with three slashes), and every block comment whose last line starts with @ts-ignore. @ts-expect-error is never reported.
  4. Reports on the line of the comment.

How to fix it

Fix the type error. When it cannot be fixed yet, use @ts-expect-error with a reason, so the comment is removed as soon as the error is gone.

src/checkout/pay.ts · TypeScript · the fix, against the flagged file
import { charge } from "./payments"; export async function checkout(cartId: string, amount: number) {Removed:   // @ts-ignoreRemoved:   return charge(cartId, amount.toFixed(2));Added:   return charge(cartId, Math.round(amount * 100));}

When it can be wrong

  • A @ts-ignore that works around a bug in a library's type definitions is still reported; switch it to @ts-expect-error.
  • In a file with @ts-nocheck, only that pragma is reported, so the @ts-ignore comments in it appear only after the pragma is removed.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • A marker added after // @ts-ignore on the same line is not read, because a Skylos directive must open its comment; the line is still reported.

    TypeScript
    // @ts-ignore  // skylos: ignore[SKY-T104] removed with payments v3
  • Put the marker in its own block comment before the directive, on the same line:

    TypeScript
    /* skylos: ignore[SKY-T104] removed with payments v3 */ // @ts-ignore
  • [tool.skylos] ignore = ["SKY-T104"] in pyproject.toml turns the rule off for the project. A baseline accepts existing findings, but it records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.