-
Notifications
You must be signed in to change notification settings - Fork 4
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
bug: hover & intellisense do not work for Options
#72
Comments
@vernak2539 - I put together a quick POC on what it would take to migrate to native typescript. Note that this is just a POC - all the tests pass, docs generate the same as before (except for one small item that seems to be related to TypeStrong/typedoc#2808), plugin works in a separate project, etc. but this should not be considered final as I would need to review tsconfig settings closer and touch up a few other things. While migrating to native TS is my recommended solution to the IntelliSense issue, all the other options are viable so deferring to you for input and decision. Just wanted to see what it would take to migrate and generally speaking, it was pretty straightforward and this does resolve the intellisense issue (the hover issue is not addressed in this POC but would be very easy to adjust to incorporate that as well). |
@techfg I'm actually of the mind that native TS is likely a good option because:
I think we could use something like tsup to do all the typescript bundling/declaration generation... Context for why it wasn't TS at the start - I wanted to test out Node.js ESM and figure out how types play into that without going full TS. Now, it seems like TS would be good.
Aftee reading your issue, seems like it's solved in v0.27.5 of typedoc?? |
I've started a PR here for this (using yours a base for the most part)! |
Awesome! I left some comments in the PR and also identified some additional issues with typedoc when using types (vs. interfaces) so created Gerrit0/typedoc-plugin-zod#8. Also updated this issue OP to track it. Once all the typedoc & typedoc plugin issues are resolved upstream, we can eliminate the workaround I added to the PR. That said, I think the PR could move forward and merge (once you are done with it) and we can handle the docs issue separately. |
@vernak2539 - Updated OP to include reference to typedoc2md/typedoc-plugin-markdown#743. This issue shouldn't stop a release but the generated docs using types (instead of interfaces) won't have a table of contents until it's addressed. Also, based on feedback from Gerrit0/typedoc-plugin-zod#8 I was able to successfully generate docs the way we want with types so added & edited some comments in the PR that should get it to where we want it to be :) |
As mentioned here, there are two issues with the Options type the plugin exports which I was finally able to reproduce:
Repro: https://stackblitz.com/edit/withastro-astro-tgi5dw6j?file=astro.config.mjs%3AL8
Note
This only occurs in dependent projects, these issues are not present in local development of this plugin directly.
Hover Issue
The reason for this is that Options is an interface and interfaces do not expand on hover (see microsoft/TypeScript#38040). In order to display properties on hover,
Options
needs to be changed to a type. This would typically be relatively straightforward but doing so creates issues with typedoc as until v0.27.0, typedoc would not link type properties in the docs. Typedoc v0.27.0 does support linking type properties, however there have been some issues with doc generation on types. Most of these have been resolved, however a couple remain:object
instead of inline type for type that is based on atypedef
typedoc2md/typedoc-plugin-markdown#720object
for its type instead of inlined typed typedoc2md/typedoc-plugin-markdown#733{@link type#property}
typedoc2md/typedoc-plugin-markdown#732Pending InvestigationResolved - hyperlink not generated for {@link type#property} TypeStrong/typedoc#2808typedoc-plugin-remark
&remark-toc
typedoc2md/typedoc-plugin-markdown#743Assuming 4 & 5 & 6 & 7 are addressed, we could migrate
Options
to a type to support hover sinceOptions
shouldn't be extended and doesn't require any of the features of interfaces. There is little benefit in making this change, other than supporting hover, and the Typescript docs actually recommend using interfaces unless a feature of type is needed but opinions on this vary and some, like Total Typescript, recommend the opposite.Intellisense Issue
The reason for this is that Options relies on importing options.mjs which relies on z.object which is a runtime method which won't run in a declaration file. This results in
Options
beingany
. In order to address this, we need to eliminate the runtime requirement.Our current approach, introduced in #40, starts with the Zod schema and infers the typescript type from it. This was done to eliminate duplication the definition of☹️
Options
and having a single source of truth/maintenance. Unfortunately, it came with an unintended consequence.The possible solutions for this are:
*.ts
files) - The benefit of this is that we can eliminate all of the hand-rolled*.d.ts
files and also avoid having to define types in jsdoc comments, both of which would significantly reduce maintenance of the library. The downside to this is that the build process would need to invoketsc
to generate the*.js
&*.d.ts
files and thenpackage.json
updated to reference thedist/
output. This isn't a big deal as it should only be one added step to the workflow you already have - these files don't need to be comitted (unless you'd want them to be).*.mjs
but usetsc
to generate the*.d.ts
files - Similar to above in terms of changes needed to build/workflow. We would still need to use jsdoc comments for types, etc.type
definition forOptions
and automate the generation of thezod
schema creation - Using a tool like ts-to-zod, instead of starting with the zod schema, we would create the zod schema manually by running the tool. Any change to the type would require that the tool be run to update the zod schema and the output included in the commit. This shouldn't happen too often so things should be fairly static but it does introduce a manual step to maintenance when making any change toOptions
. The thinking here is that the type would be exported directly instead of the inferred type from zod being exported.options.d.ts
to include thez.ZodType
directly instead of importing theOptionsSchema
const and inferring. This eliminates the runtime requirement ofz.object
, however maintaining the code for thez.ZodType
is much higher maintenance than just using thez.object
to create the schema.Options
andOptionsSchema
separately as it was prior to chore: single source of truth for options #40. Outside of having too maintain in two places, this would not require any other changes to the plugin and/or workflows.@vernak2539 - Sorry for the long explanation on this! After reviewing all the above, please let me know your thoughts on:
Options
as an interface or migrate to a type in order to support hover?Options
as an interface, intellisense should work.*.ts
) files as outside of adding a build step to the existing workflow, it simplifies a lot of things and reduces overall cost of maintenance of the plugin.Thanks!
The text was updated successfully, but these errors were encountered: