Typing a JavaScript array of literals with that type turns it into a tuple - a poor man's replacement for TypeScript's as const:
has type string[],
const arr = /** @type {['foo']} */ (['foo']);
has type ['foo'].
While looking into this I learned that since TypeScript version 4.5, you can actually do this instead:
const arr = /** @type {const} */ (['foo']);
which is much nicer. But the old way is not an unnecessary type assertion.
Expected behavior
No warning or give a more specific warning and autofix to /** @type {const} */.
Actual behavior
The rule reports the type assertion as unnecessary and the autofix removes it, changing the type.
ESLint Config
import { jsdoc } from 'eslint-plugin-jsdoc';
export default [
jsdoc({
rules: {
'jsdoc/no-unnecessary-type-assertion': 'error',
},
}),
];
ESLint sample
const arr = /** @type {['foo']} */ (['foo']);
Environment
- Node version: 24.20.0
- ESLint version: 10.9.1
eslint-plugin-jsdoc version: 64.3.3
Typing a JavaScript array of literals with that type turns it into a tuple - a poor man's replacement for TypeScript's
as const:has type
string[],has type
['foo'].While looking into this I learned that since TypeScript version 4.5, you can actually do this instead:
which is much nicer. But the old way is not an unnecessary type assertion.
Expected behavior
No warning or give a more specific warning and autofix to
/** @type {const} */.Actual behavior
The rule reports the type assertion as unnecessary and the autofix removes it, changing the type.
ESLint Config
ESLint sample
Environment
eslint-plugin-jsdocversion: 64.3.3