-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Nameless @typedef
has implicit any error on the associated identifier
#36375
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
Comments
noImplicitAny
to not error on @typedef
jsdoc@typedef
has implicit any error on the associated identifier
Currently the error is correct, since the value EventTargetEvent actually does have the type @TimvdLippe is there closure code of the form /** @typedef {{ x: number }} */
export let T = class {
} where the class does not have an |
All
|
I looked at the implementation of the compiler and it seems rather straightforward to fix this. E.g. it would check, during variable initialization, if the jsdoc has a typedef. If so, set the variable to Do you mind if I try to create a PR for this issue with the above semantics? |
Typedefs have two forms: specify a name in the `@typedef` declaration or use the name of the variable declaration it is attached to. Since `@typedef` types should only live in the type space, any reference to a variable that has a `@typedef` attached to is illegal. As such, assign it the `never` type if the `@typedef` itself does not specify a name. Fixes microsoft#36375
WIP PR at #36454 which passes all tests. |
@sandersn what's the desired behavior? |
I don't think this bug is worth fixing, though, because the new code only benefits (1) closure code bases (2) with noImplicitAny: true. I don't believe there are many of these. I don't think that justifies the support cost of the new code. |
Looks like #28162 includes the error I suggested, plus a lot more, already. |
I still don't think this bug is worth fixing, for the same reason I gave before: compiling closure code bases with noImplicitAny: true is not a scenario that we've planned for. Instead I think it's better to convert to TS with noImplicitAny: false, and then follow up by turning on strict flags one at a time. Alternatively, automatic insertion of |
TypeScript Version: 3.7.5
Search Terms: typedef, jsdoc, noImplicitAny
Code
Expected behavior:
No error when compiling with
noImplicitAny
Actual behavior:
Variable 'EventTargetEvent' implicitly has an 'any' type.
Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=2&pc=22#code/PQKhCgAIUgBAXAngBwKYBNUDNIG8CEu6AhvMQFyQB2ArgLYBGqATgL6tQjDioAeyAe2bxIAG1QiAogDdUVeABVizAOYSZc+AG4gA
Related Issues: Originally discussed with @sandersn in #19983 who requested a separate issue
The text was updated successfully, but these errors were encountered: