Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNameless `@typedef` has implicit any error on the associated identifier #36375
Comments
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
All
|
This comment has been minimized.
This comment has been minimized.
|
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
This comment has been minimized.
This comment has been minimized.
|
WIP PR at #36454 which passes all tests. |
This comment has been minimized.
This comment has been minimized.
|
@sandersn what's the desired behavior? |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Looks like #28162 includes the error I suggested, plus a lot more, already. |
TypeScript Version: 3.7.5
Search Terms: typedef, jsdoc, noImplicitAny
Code
Expected behavior:
No error when compiling with
noImplicitAnyActual 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