-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
jsdoc/valid-types throwing warning when using import syntax #604
Comments
You can either:
Bear in mind that if switching to TypeScript, TypeScript (and thus our "typescript" mode) does not support all of jsdoc. See https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html for the supported tags and types. The mode/dialect you choose depends on how you intend to use jsdoc. Closing as that should resolve, though feel free to comment further as needed. |
Hello, I have the same problem. This used to work with eslint-plugin-jsdoc version 27.1.2. |
@janokacer : Please read the comments for short threads like this one before posting. Thanks. |
@brettz9 I do not find any of the 3 options great for us, do you have some other recommendation? Let me give an example: For 1) we have this code below. In e.g. VS Code this does not give IntelliSense when hovering /** @typedef {module:express} Express */
/**
* @param {Express.Request} options.log.req - Express request object
*/
function foo(options) { Both 2) and 3) seem to indicate we cannot use all JSDoc features, which we want. Is there any way for
|
Did you try item no. 3? Otherwise, I think this is really more of a bug (or feature request) for VS Code. But with Microsoft being behind VS Code and TypeScript, and with TypeScript indicating they will not support |
I understood item no.3 that neither |
I think tools are likely to be built for either jsdoc or TypeScript. We normally recommend one or the other of the modes. While we do have the "permissive" mode which tries to allow you to do what we think is the more permissive, in case you have tools that support both well or if you really want to use the semantics of both together. But most projects are probably going to want to ensure that the features they are using are going to be supported in the tools they are using (e.g., If you know the tools you want to use, and are enforcing one mode consistently, you will have less reason to be disappointed when it comes time to build your documentation. (It's not always clear what "support" means anyways; a tool may not complain about something, but it might not display it very intelligently, for example.) Determining our "permissive" mode wasn't always clear in some cases though; although I can't think of the specific example now, it was not possible in every situation to say something like "just support both To get the advantages of both, you will either need to build tools yourself that utilize them, or you can indicate your support or subscribe to the issues where TypeScript (or Closure or jsdoc) is seeking to support more missing features. For newcomers, I would probably suggest looking into TypeScript-flavor jsdoc ("typescript" mode if you don't need to add a TypeScript parser) because it has a very active community, it has actively-maintained tooling, and because I think such trends tend to win out in the long term (if they haven't already). That doesn't even mean you have to use TypeScript-only features (in fact, I think jsdoc blocks can give you a lot of the benefits without needing to express types everywhere)--I'm here merely recommending the TypeScript-style jsdoc mode. I'd personally recommend confining yourself to it unless you have an old project or some other reason to stick with jsdoc mode. |
Appreciate the answer! I re-read the comment twice, but am not 100% sure what I should do in my case. I.e a VS Code user using JS Doc and ESLint with eslitn-plugin-jsdoc, but no TypeScript. It sounds like I should use
In e.g. VS Code, they do heavily support both TypeScript (for IntelliSense) as well as JSDoc. If you type |
If your documentation tool is JSDoc, you probably want to use But it's your call, I can't make the decision for you, even while I have made a limited personal opinion that "typescript" mode might be the most future-proof for new projects, at least if one wishes TypeScript-aware tools to fully "support" the tag beyond just not complaining when it is used.
Yes, I am aware that tools can handle them generically in some sense. But that doesn't mean they follow the You are welcome to try permissive mode if you really wish to use all of the features, but as there is no official "permissive" mode to go by, there are no guarantees we will maintain that to continue to work for your particular needs or even that we will indefinitely maintain it if circumstances change to make it hard to maintain. But right now, it isn't hard for us to offer it, so if you don't mind the risk that it won't work suitably for tooling, then go ahead with that unless you come to find a need to restrict your project. You might look at https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html , for example, to see that TypeScript doesn't "support" certain tags, but that doesn't mean all of its tools can't be made to accept them in some sense either. You have to investigate that yourself. |
I understand I might have asked a bit too much here, but I found it valuable as a large portion of users use VS Code with the built-in JSDoc and thus might stumble on this. I will try |
Your questions were fine and understandable; I just want to make clear about not going on too much here in case you are still in doubt about it. And I should say I am sometimes personally in doubt about it despite working on such a project! It isn't easy when the project we are targeting is not completely dead, but is not very active or able to be responsive to questions, and another project with a different but overlapping scope is active and the two are in a relative stasis with it. But yeah, "typescript" is probably the way to go, at least if you don't want to be disappointed with TypeScript not doing what you think it should with the syntax if you end up using it (though tools like typedoc at least will still pass your custom tags through). We could switch from the default at some point, e.g., if the documentation tool |
Btw, one problem I'm running into with typedoc/typescript is that one might have to refactor even plain JavaScript to get things to work. It is not perfectly intelligent (or it is overly opinionated) in requiring things like initializing destructured values, not being able to overwrite a property in some cases as it corrupts the type, etc. Using the jsdoc documentation tool comes at the cost of not getting all of the type validation, and presumably in not using TS-friendly jsdoc, one might lose the autocomplete/tooltips (though ternjs may help), etc., but it also doesn't require you to change your JavaScript to suit the tool. |
Expected behavior
Plugin should allow us to import types from separate file without warning/error.
Actual behavior
ESLint Config
ESLint sample
Environment
eslint-plugin-jsdoc
version: 28.6.1The text was updated successfully, but these errors were encountered: