quick-lint-js

Find bugs in JavaScript programs.

E0261: TypeScript non-null assertions are not allowed in JavaScript

In TypeScript, ! after a expression is a non-null assertion. It is a syntax error to write a non-null assertion in JavaScript:

/** @type {string} favoritePowerRanger */
let favoritePowerRanger;
if (player.hasFavoriteColor) {
  favoritePowerRanger = player.favoriteColor!;
} else {
  favoritePowerRanger = "(unknown)";
}

To fix this error, remove the !:

/** @type {string} favoritePowerRanger */
let favoritePowerRanger;
if (player.hasFavoriteColor) {
  favoritePowerRanger = player.favoriteColor;
} else {
  favoritePowerRanger = "(unknown)";
}

Documentation for other errors