Skip to content

no-undefined-types does not consider @template definitions with type constraints #428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Elberet opened this issue Nov 12, 2019 · 7 comments

Comments

@Elberet
Copy link

Elberet commented Nov 12, 2019

When running in typescript mode (settings.jsdoc.mode = "typescript"), template types with type constraints are ignored by the no-undefined-types rule:

/**
 * Run callback when hooked method is called.
 *
 * @template {BaseObject} T
 * @param {T} obj - object whose method should be hooked.
 * @param {string} method - method which should be hooked.
 * @param {(sender: T) => void} callback - callback which should
 * be called when the hooked method was invoked.
 */
function registerEvent(obj, method, callback) { ... }

In the example above, the type constraint on T results in jsdoc/no-undefined-types emitting a warning "The type 'T' is undefined". See the Typescript handbook for more examples on typed templates.

@brettz9
Copy link
Collaborator

brettz9 commented Nov 12, 2019

Fixed by 5f48821

@brettz9 brettz9 closed this as completed Nov 12, 2019
@brettz9
Copy link
Collaborator

brettz9 commented Nov 12, 2019

And released with https://github.com/gajus/eslint-plugin-jsdoc/releases/tag/v17.1.2 .

@Elberet
Copy link
Author

Elberet commented Nov 12, 2019

😱

Now that's what I call response time. 👍

@snowteamer
Copy link

There is still a false positive when the type parameter is used inside the function:

/**
 * @template T
 * @param {T} arg
 * @returns {[T]}
 */
function example(arg) {
	const result =  /** @type {[T]} */ (new Array());
	result[0] = arg;
	return result;
}

The type 'T' is undefined. (eslint(jsdoc/no-undefined-types) [7, 1]

@brettz9
Copy link
Collaborator

brettz9 commented Jun 1, 2020

@snowteamer : Thank you. Could you please file a new issue? Also if know of docs showing the scope of where the template name can be used?

@wycats
Copy link

wycats commented Jun 2, 2020

I hit the same issue today!

@Elberet
Copy link
Author

Elberet commented Jun 9, 2020

See also #559 for the template type scope issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants