Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/rules/valid-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -888,5 +888,19 @@ function quux() {
/**
* @returns {@link SomeType}
*/

/**
* @template {string} Selector
* @template {keyof GlobalEventHandlersEventMap} TEventType
* @template {Element} [TElement=import('typed-query-selector/parser').ParseSelector<Selector, HTMLElement>]
* @param {Selector} selector
* @param {TEventType} type
* @param {import('delegate-it').DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>} callback
* @param {Omit<AddEventListenerOptions, 'once' | 'signal'>} [options]
* @returns {void}
*/
export function onGlobalEvent (selector, type, callback, options) {
delegate(document, selector, type, callback, options)
}
````

11 changes: 9 additions & 2 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,15 @@ export default iterateJsdoc(({

if (hasNameOrNamepathPosition) {
if (mode !== 'jsdoc' && tag.tag === 'template') {
for (const namepath of utils.parseClosureTemplateTag(tag)) {
validNamepathParsing(namepath);
if (!tryParsePathIgnoreError(
// May be an issue with the commas of
// `utils.parseClosureTemplateTag`, so first try a raw
// value; we really need a proper parser instead, however.
tag.name.trim().replace(/^\[?(?<name>.*?)=.*$/v, '$<name>'),
)) {
for (const namepath of utils.parseClosureTemplateTag(tag)) {
validNamepathParsing(namepath);
}
}
} else {
validNamepathParsing(tag.name, tag.tag);
Expand Down
17 changes: 17 additions & 0 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1869,5 +1869,22 @@ export default /** @type {import('../index.js').TestCases} */ ({
*/
`,
},
{
code: `
/**
* @template {string} Selector
* @template {keyof GlobalEventHandlersEventMap} TEventType
* @template {Element} [TElement=import('typed-query-selector/parser').ParseSelector<Selector, HTMLElement>]
* @param {Selector} selector
* @param {TEventType} type
* @param {import('delegate-it').DelegateEventHandler<GlobalEventHandlersEventMap[TEventType], TElement>} callback
* @param {Omit<AddEventListenerOptions, 'once' | 'signal'>} [options]
* @returns {void}
*/
export function onGlobalEvent (selector, type, callback, options) {
delegate(document, selector, type, callback, options)
}
`,
},
],
});
Loading