Skip to content

Commit b47779c

Browse files
committed
fix(no-undefined-types): treat param names as defined; fixes #1591
1 parent c72f8b0 commit b47779c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/rules/no-undefined-types.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,5 +1115,15 @@ const Severities = {
11151115
*/
11161116

11171117
export default Severities;
1118+
1119+
/**
1120+
* @template {unknown} T
1121+
* @param {unknown} value
1122+
* @param {...T} validValues
1123+
* @returns {value is T}
1124+
*/
1125+
const checkIsOnOf = (value, ...validValues) => {
1126+
return validValues.includes(value);
1127+
};
11181128
````
11191129

src/rules/noUndefinedTypes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,16 @@ export default iterateJsdoc(({
466466
return utils.isNamepathOrUrlReferencingTag(tag);
467467
}).map(tagToParsedType('namepathOrURL'));
468468

469+
const definedNamesAndNamepaths = new Set(utils.filterTags(({
470+
tag,
471+
}) => {
472+
return utils.isNameOrNamepathDefiningTag(tag);
473+
}).map(({
474+
name,
475+
}) => {
476+
return name;
477+
}));
478+
469479
const tagsWithTypes = /** @type {TypeAndTagInfo[]} */ ([
470480
...typeTags,
471481
...namepathReferencingTags,
@@ -520,6 +530,7 @@ export default iterateJsdoc(({
520530
if (type === 'JsdocTypeName') {
521531
const structuredTypes = structuredTags[tag.tag]?.type;
522532
if (!allDefinedTypes.has(val) &&
533+
!definedNamesAndNamepaths.has(val) &&
523534
(!Array.isArray(structuredTypes) || !structuredTypes.includes(val))
524535
) {
525536
const parent =

test/rules/assertions/noUndefinedTypes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,5 +1891,18 @@ export default /** @type {import('../index.js').TestCases} */ ({
18911891
export default Severities;
18921892
`,
18931893
},
1894+
{
1895+
code: `
1896+
/**
1897+
* @template {unknown} T
1898+
* @param {unknown} value
1899+
* @param {...T} validValues
1900+
* @returns {value is T}
1901+
*/
1902+
const checkIsOnOf = (value, ...validValues) => {
1903+
return validValues.includes(value);
1904+
};
1905+
`,
1906+
},
18941907
],
18951908
});

0 commit comments

Comments
 (0)