SKY-T104 · Quality, structure and performance
TypeScript compiler suppression directive
// @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
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
import { charge } from "./payments"; export async function checkout(cartId: string, amount: number) { // @ts-ignore return charge(cartId, amount.toFixed(2));}What Skylos leaves alone
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
// @ts-nocheckexport function legacyTotal(items) { return items.reduce((sum, item) => sum + item.price, 0);}Not flagged
// @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
- Runs with
--qualityon TypeScript and JavaScript files. Declaration files (.d.ts) and generated files (underbuild,dist,generatedorvendorfolders,*.gen.*or*.generated.*names, or with a generated-code header) are skipped. - Reads the comments at the top of the file, before the first statement. When the last
// @ts-checkor// @ts-nocheckamong them is@ts-nocheck, it reports that comment once, HIGH, and nothing else in the file. - Otherwise it reports MEDIUM every
// @ts-ignorecomment (also with three slashes), and every block comment whose last line starts with@ts-ignore.@ts-expect-erroris never reported. - 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.
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-ignorethat 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-ignorecomments 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-ignoreon 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 v3Put 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"]inpyproject.tomlturns 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.