I expected that this code snippet does not cause any lint error:
function retrieveHexCode(colorName) {
const hashmap = {
white: '#fff',
};
// šļø Lint error: The type 'hashmap' is undefined.
/** @typedef {keyof typeof hashmap} KeyOfHashmap */
// It seems like normal variables are not recognized.
/** @typedef {typeof hashmap} TypeOfHashmap */
const colorHexCode = hashmap[/** @type {KeyOfHashmap} */ (colorName)];
return colorHexCode ?? '#000';
}
const hashmapTwo = {
white: '#fff',
};
// šļø However, the error does not occur outside of function scope.
/** @typedef {typeof hashmapTwo} TypeOfHashmapTwo */
Actual behavior
In the above snippet, hashmap is reported as undefined by jsdoc/no-undefined-types. This only happens inside the function scope, please take a look at the reproduction playground for more details. Intellisense was still working properly.
Reproduction: https://stackblitz.com/edit/vitejs-vite-d1gqkb
Expected behavior
I expected that this code snippet does not cause any lint error:
Actual behavior
In the above snippet,
hashmap
is reported asundefined
byjsdoc/no-undefined-types
. This only happens inside the function scope, please take a look at the reproduction playground for more details. Intellisense was still working properly.ESLint Config
ESLint sample
See ā https://stackblitz.com/edit/vitejs-vite-d1gqkb or check the code in "Expected behavior".
Environment
eslint-plugin-jsdoc
version: 50.5.0