-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Typescript types should be supported in jsdoc type positions #145
Comments
PRs welcome. |
I have an initial PR, for typeof and import types, up at jsdoctypeparser/jsdoctypeparser#51. I'll create a matching PR here, but it'll depend on a new version of jsdoctypeparser being available. |
I would be open to bringing JSDoc parser into this library as I can see it becoming a common bottleneck for changes (if anyone is up for the challenge). |
I like the jsdoctypeparser parser code itself, although it is quite old and hasn't been touched in 2.5 years or so. Maybe it just needs more maintainers. Its licence is MIT, which I think is compatible with that of eslint-plugin-jsdoc, so copying the source would just be a technical problem, not a legal one. |
This would be amazing. I could finally get rid of all the |
I haven't heard back from my PR on jsdoctypeparser, so I think moving the code here is a good idea. I'll take a look when I have time, which may be a few weeks. |
Also, this should support allowing |
@ExE-Boss I think that would be determined by Also, for Typescript, I don't recommend putting types in JSDoc since the types should be in the signature. |
@gajus I read about licencing and I am not sure whether it's OK to copy an MIT-licensed project into a BSD-licensed one. It might be, but I'm not sure how to modify the licence of eslint-plugin-jsdoc, and I don't think that's a good idea either. Probably the right thing is to contact @Kuniwak and see whether some owners/contributors from this project could be added to the owners of jsdoctypeparser. Is that something you are interested in? If so I'll contact @Kuniwak and see what they think about adding you, me or @brettz9 (who is the only common contributor between these two projects). Otherwise, it would probably be safer to fork jsdoctypeparser and re-publish it as jsdoctypeparser2. Either way I think it should stay a separate project. Another option is to use a completely different, possibly new, parser. I thought about the Typescript parser, but it's unlikely to ever support the standard jsdoc import syntax ( cc @brettz9 |
I meant when I use the TypeScript compiler to type check JavaScript code. |
@sandersn : I support forking jsdoctypeparser as a new project. Though he was engaging me for a while, the project owner suddenly stopped and I haven't heard back from him in quite a while. I have an open PR to actually add the "event:" prefix you happen to have mentioned. If he agreed to add us as owners, I'd be happy to at least merge that though. :) But I'd advise not waiting too long for a response, as it has already been a while for my requests. IANAL, but it seems pretty clear that the very permissive MIT is compatible with this project's BSD-3-clause (one could not, however, incorporate its BSD-3-clause content into an MIT licensed-project and keep it licensed as MIT (only), as the BSD-3-clause has an additional clause about not being used for endorsement). |
I suggest to copy the code (and LICENSE) into this library. Alternatively, if either of you want to take ownership of a separate project, I am happy to use that too, as long as there are multiple contributors. |
I'm not sure what it means to append the MIT licence to the BSD licence, but it's not standard. I'm uncomfortable doing that. I'll contact the owner and see if @brettz9 and I can get on the owner list. In the meantime, after I've made a few fixes I'll start publishing my fork as jsdoctypeparser2 until I hear back from the owner. |
Or publish it as @sandersn/jsdoctypeparser, in the same way @pnpm’s fork of cmd-shim is available as @zkochan/cmd-shim |
Update: I heard back from @Kuniwak via twitter and they suggested setting up a jsdoctypeparser organisation, then transferring ownership of the repo there. I'll do that when I have time. I'm a bit busy with the Typescript 3.4 release today, so it may not happen until Monday. |
OK, the jsdoctypeparser repo is now at https://github.com/jsdoctypeparser/jsdoctypeparser and I pushed a new major version, 3.0.0, whose purpose is to prevent users from upgrading automatically. It doesn't have any other changes. |
Thank you so much, @sandersn for moving this forward! As per my comment at jsdoctypeparser/jsdoctypeparser#50 (comment) , I'd hope this would optional, unless you feel motivated to help maintain the fairly inactive jsdoc project to support processing (and display) of these types! :) |
Yes, I am motivated! I would like the entire ecosystem to work with Typescript correctly.
|
Awesome on both counts--the release and changing the ecosystem sounds great... I mean the original jsdoc, though you might check out that it appears there is already a PR: jsdoc/jsdoc#1560 |
And if JSDoc does support Typescript already, I see no evidence of it at http://usejsdoc.org/tags-type.html (except of course to the extent Typescript is using JSDoc!) |
Should tracking be done here for avoiding using constructs from Typescript or JSDoc which are redundant to the other as referenced in jsdoctypeparser/jsdoctypeparser#50 (comment) (if the implementers of the Typescript support can begin support for such a rule while preparing PRs to add Typescript support)? |
A followup question for disallowing type syntax that is redundant between TS and JSDoc: Are these options sufficient?
I don't know anything about eslint yet but it looks pretty straightforward to add rules and configs, based on a quick look at index.js. Anything I should know before starting? |
If I may, what's the status on this? I'm getting a warning about a syntax error in (FWIW, splitting the import into a |
@Elberet : This looks like an issue with Note there is an issue for better supporting TypeScript types at jsdoctypeparser/jsdoctypeparser#50 , but in this case, Btw, FWIW, for experimenting with types supported by |
Thanks, I guess I'll By the way, the full background is this: /** @typedef {import("./BaseFoo").default} BaseFoo */
/** @type {typeof BaseFoo} */
get Foo() { return this.dynamicChildClassOfBaseFoo } This gets linted correctly, but Typescript (and by extension VSCode's code completion) believes /** @type {new() => BaseFoo} */ Works in both, but incorrectly documents the
|
The jsdoctypeparser demo doesn't test traversal, and it looks like that is the issue there. I encourage you to file these concerns on jsdoctypeparser. |
@Elberet : The |
Off topic somewhat, but relevant to TS in jsdoc... In In support of this, in the case of the nullable version at least, a link is given to Closure source showing where it is still used: https://github.com/google/closure-library/blob/master/closure/goog/net/tmpnetwork.js#L50 . And Closure docs mention:
@type {Object?} There are still postfixes for So rather than removing them from |
Oh, I see from jsdoctypeparser/jsdoctypeparser#50 (comment) that TS supports them even into 4.0, so I think making On another TS subject... While it appears from jsdoctypeparser/jsdoctypeparser#58 (comment) that |
We have made a switch (in v35.1.0) from He has done the highly impressive work of covering our jsdoctypeparser test cases along with catharsis'. See jsdoc-type-pratt-parser/jsdoc-type-pratt-parser#4 (comment) for the few remaining TypeScript apparently remaining. |
Thanks for the update. I think this is the right direction since I haven't had time to work with jsdoc type parsing for quite a while. |
Thanks! I don't have time to work on it right now but I'll let you know if I start up again and need write access. |
@brettz9 should this one be closed? |
@thernstig : I think with a few features missing still in |
@thernstig : updated |
Any possible to make |
#99 is closed but the warning @JounQin mention still happens using the default mode. In my case it's with
...
{
"env": {
"node": true,
"es6": true
},
"extends": [
"plugin:jsdoc/recommended"
],
"files": ["karma.conf.js", "**/*.{cjs,mjs}"],
"excludedFiles": ["src/app/**/*"],
"parserOptions": {
"ecmaVersion": 2022
},
"overrides": [
{
"files": ["**/*.mjs"],
"parserOptions": {
"sourceType": "module"
}
}
]
},
...
...
/**
*
* @param {NodeJS.Signals} signal Señal emitida
*/
const exitGracefully = (signal) => {
logger.info(`${signal} signal received`);
shutdownServer(0);
};
/**
*
* @param {Error} error Error no manejado
* @param {NodeJS.UncaughtExceptionOrigin} signal Señal emitida
*/
const onUncaughtException = (error, signal) => {
logger.error(`${signal} signal received`);
logger.error(error);
shutdownServer(1);
};
process.on("SIGTERM", exitGracefully);
process.on("SIGINT", exitGracefully);
process.on("uncaughtException", onUncaughtException);
... |
@gian1200 : Since TS checks this anyways, the rule If you wish to discuss further, let's do so on #888. |
Typescript types should be supported. Most of the work needs to occur in
Kuniwak/jsdoctypeparser(now, jsdoc-type-pratt-parser)), but there will likely be some code needed here as well. At the very least, some tests need to be added to make sure that Typescript types work.Related:
typeof C
type expression not supported #133 - support for typeof, which is understood by every JS type checker, not just Typescript. Typescript types should parse correctly jsdoctypeparser/jsdoctypeparser#50 - the bug tracking the actual fixWant to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: