-
Notifications
You must be signed in to change notification settings - Fork 701
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
Clarification of how to properly include typedefs in documentation built for an ES module. #2044
Comments
This is, accidentally I think, the best argument I have seen for TypeDoc "automatically" including non-exported types... TypeDoc is working as intended here - your module entry point re-exports import { type SomeDataStructure } from "your-module" Because TypeDoc only walks exports from your entry point(s), and Two commonly used plugins are: |
Thanks @Gerrit0 - I think that https://www.npmjs.com/package/typedoc-plugin-missing-exports can work here, but it does come with some limitations and flaws. I wonder whether you think this should be a supported usage for TSDoc/typedoc? If so, is there an avenue to pursue for advocating a change to the core behavior? A limitation of the JSDoc If that feature request were made, would it be a |
This is not true. // @filename: jsdoc.js
/** @typedef {string} MyString */
export const abc = 123
// @filename: test.ts
import { MyString, abc } from "./jsdoc.js"
export const x: MyString = abc // Error: Type 'number' is not assignable to type 'string'. The problem arises because TypeScript doesn't have a clean way to re-export types via JSDoc. The above is equivalent to: // @filename: jsdoc.ts
export type MyString = string
export const abc = 123
// @filename: test.ts
import { MyString, abc } from "./jsdoc.js"
export const x: MyString = abc
TypeDoc could support this better by detecting type "re-exports" done with A "real" type re-export feature would have to come as an upstream feature from TypeScript. microsoft/TypeScript#22160 is vaguely related, but really highlights that using JSDoc for types is truly a second class citizen in the TS world... |
Thanks for your clarification @Gerrit0 - there's definitely some complexity and competing objectives here so I understand why this is a sticky situation. At the end of the day I think it's uncontroversial that a The other path would be more of a pure documentation solution where the typedef - under certain circumstances - could still be included in the generated docs even though it isn't explicitly exported. That seems perhaps like the path of less resistance and is similar to what the https://www.npmjs.com/package/typedoc-plugin-missing-exports plugin does but with a more specific and limited scope of impact. It doesn't seem too controversial to me that typedocs might support the following option:
It doesn't seem like there are upstream technical blockers towards |
TypeDoc's goal is to create documentation which is consistent with what is available to your module's consumers. The missing exports plugin provides an escape hatch for those who can't/won't export the types necessary for their users. I sympathize with people stuck using JSDoc types (I'm one of them at work atm...) but really don't want to compromise that design goal... |
Thanks for your perspective, I do have a disagreement with that statement though: When my module explicitly exports a class via The type of the data object the class takes as its constructor is an essential part of the documentation for that explicitly exported class, regardless of whether the typedef itself was explicitly exported (which is not possible in JSDoc) or not. |
This is where we disagree, since the user can't |
Is the purpose of API documentation not to inform the user how to use the exported classes and functions of a module? What use is API documentation if the docs don't tell you how to construct It feels like your perspective loses sight of the fundamental purpose for documentation in favor of turning a (surmountable) technical limitation into a philosophical line in the sand that ultimately doesn't serve the end user. I hope my feedback on this area is useful to you and that your perspective may shift over time, but either way thank you for your time spent looking into this matter and for your development of this codebase. |
I agree strongly w/ @aaclayton here; if knowledge of the shape is necessary for use of the library then the shape should be documented in the API docs. Whether or not the type is made available for explicit use in consuming code isn't really relevant; it's an implicit dependency and the user needs to know the shape either way. The existing missing-exports plugin works alright for this, but has some annoying bugs around inline imports. It'd be really helpful if this were first-class behavior. |
I think it would be a shame for the discussion in this thread to be treated as "closed" even though the original question was answered. I really believe this represents a shortcoming in the current functionality of documentation generators and it would be great to keep this issue open to reflect the possibility to improve the software, even if those improvements are not prioritized in the short term. |
I continue to think it's a mistake for this issue to be treated as "closed". This is a major limitation which cripples the functionality of typedoc as a documentation generator with JSDoc interoperability. Please reconsider whether more discussion can occur here which might lead to a potential solution path. |
If this were to be implemented in TypeDoc itself, rather than typedoc-plugin-missing-exports, it would use (roughly) the same implementation, which makes "major limitation" seem like a major overstatement. The functionality you want is already available... If something is wrong with that plugin, issues should be filed there, I certainly don't want to bring functionality into TypeDoc itself which is half baked. A large part of my resistance to this feature is that it encourages people to be sloppy with both what is exposed by their library and what they export. Requiring that documented members be exported means that:
Is it frustrating for your JSDoc use case? Absolutely, but the plugin does exist, and frankly, JSDoc is a second class citizen in the TypeScript world... (having this option live out in a plugin lets me see how many people are actually using it, which is higher than I expected at 6% of users, but well below typedoc-plugin-markdown numbers, which certainly doesn't belong in TypeDoc itself, popularity isn't everything) |
Thank you for the response @Gerrit0 - we are using the |
Bugs over there are the best place, that way they're more easily tracked, thanks! |
Search terms
typedef, esmodule, class, "referenced but not included in the documentation"
Question
I am using typedoc to document an ESModule. An example file in that module defines a class and its constructor parameter(s) as follows (this is a simplified example):
File 1: Class Declaration -
some-class.mjs
The documentation is built by targeting another file which is the entry-point that aggregates exports for different components of the module:
File 2: Module Entrypoint -
module.mjs
What Goes Wrong?
When trying to build documentation for the module the following warning is displayed:
Documentation is built for
SomeClass
, but the data type of its constructor parameter is not documented nor is theSomeDataStructure
typedef available for inspection in the resulting documentation.I realize this is a somewhat uncommon use case since the source of the module is not TypeScript but rather an ESModule directly, but this use case is portrayed as being supported by https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#typedef-callback-and-param.
Is this a typedoc bug? Is this a problem with the way I have structured the module code? Thanks for your guidance.
The text was updated successfully, but these errors were encountered: