// @ts-expect-error on its own line says "the next line has an error, on purpose". TypeScript silences the errors on that line, and if the line has none, it reports the comment itself: TS2578, "Unused '@ts-expect-error' directive". It arrived with TypeScript 3.9.
That makes it the safe way to keep a known error for now: when someone fixes the line, the comment fails npm run lint and gets removed, instead of lingering to hide the next mistake the way // @ts-ignore can.
At a glance
| Write | // @ts-expect-error |
|---|---|
| Applies to | The line after the comment |
| With checkJs on | Silences the errors on the next line, and is itself an error (TS2578) when that line has none |
| With checkJs off | Nothing, unless the file starts with // @ts-check |
Examples
/** @param {number} cents */
function formatPrice(cents) {
return `$${(cents / 100).toFixed(2)}`;
}
// @ts-expect-error: the old API passed strings
console.log(formatPrice("1999"));
// This call was fixed, so the directive above it now has nothing to silence.
// @ts-expect-errorerror TS2578: Unused '@ts-expect-error' directive.
console.log(formatPrice(1999));jsconfig.json for this example
{
"compilerOptions": {
"checkJs": true,
"noEmit": true,
"strict": true,
"target": "es2022",
"module": "nodenext",
"types": []
},
"include": [
"*.js"
]
} Say why
Text after the directive on the same line is ignored by the checker, so write the reason there: // @ts-expect-error: the old API passed strings. The first call in the example does exactly that.
It has to be on the line above
The directive applies to the line that follows it. A block comment at the start of the same line, /* @ts-expect-error */ formatPrice("1"), does not count: in TypeScript 5.9 the error on that line is still reported, and so is the directive, as unused.
Gotchas
- Tests that check a function rejects bad input are the classic use:
// @ts-expect-erroraboveformatPrice("1999")in a test file documents the type and proves it still holds. - In a file that is not checked (no
checkJs, no// @ts-check) the comment does nothing and is never reported.
Sources
- JS Projects Utilizing TypeScript · TypeScript handbook
- TypeScript 3.9 release notes · TypeScript handbook
Last reviewed 20 October 2026.