TypeStrong / typedoc

Documentation generator for TypeScript projects.
https://typedoc.org
Apache License 2.0
7.77k stars 702 forks source link

TypeDoc 0.27 Beta #2763

Open Gerrit0 opened 2 weeks ago

Gerrit0 commented 2 weeks ago

TypeDoc 0.27 is now in beta! :tada:

Please try it out and report any issues in new issues:

npm install --save-dev typedoc@beta

The full release will be made on 2024-11-21 (TS 5.7 release date, may be pushed if TS pushes)

This release mainly focuses on improved flexibility for type conversion and several improvements to the default theme, but also makes some changes to output.

Conversion Flexibility

TypeDoc uses the compiler to retrieve the types of documented members, and converts them into a simplified structure for rendering. Historically, not much flexibility has been exposed to control this behavior. v0.24 added support for @interface to tell TypeDoc to treat a type alias as if it was an interface, and @namespace to convert variables as namespaces. v0.27 extends this support with some additional tags:

Default Theme Changes

This release includes quite a few quality of live improvements to the default theme:

Reworked Modules Page

Modules/namespace pages have been re-worked to be more generally useful. The @summary tag can now be used to define a "short summary" for a reflection, which will be rendered on the modules page, or the useFirstParagraphOfCommentAsSummary option can be set to automatically use the first paragraph of a reflection's comment as the summary. Re-exports (like CommentStyle below) will be rendered with an arrow pointing to the canonical export.

image

Expanded References

If @expand is used on a type alias or interface, references to it will be expanded. In the screenshot below the @expand tag was placed on InlineTagDisplayPart and RelativeLinkDisplayPart. This screenshot also shows how TypeDoc can render comments for each branch of a union at the root level of a type alias.

Code ```ts /** * Represents a parsed piece of a comment. * @category Comments * @see {@link JSONOutput.CommentDisplayPart} */ export type CommentDisplayPart = /** * Represents a plain text portion of the comment, may contain markdown */ | { kind: "text"; text: string } /** * Represents a code block separated out form the plain text entry so * that TypeDoc knows to skip it when parsing relative links and inline tags. **/ | { kind: "code"; text: string } | InlineTagDisplayPart | RelativeLinkDisplayPart; /** * Represents an inline tag like `{@link Foo}` * * The `@link`, `@linkcode`, and `@linkplain` tags may have a `target` * property set indicating which reflection/url they link to. They may also * have a `tsLinkText` property which includes the part of the `text` which * TypeScript thinks should be displayed as the link text. * @category Comments * @expand */ export interface InlineTagDisplayPart { kind: "inline-tag"; tag: `@${string}`; text: string; target?: Reflection | string | ReflectionSymbolId; tsLinkText?: string; } ```

image

Smarter Code Rendering

When TypeDoc renders types, it used to apply some very basic rules about when to wrap a type to multiple lines, namely deciding to wrap object types and top level unions on every line, and placing all other types on the same line. This mostly worked, but could also cause very messy rendering. TypeDoc now uses an algorithm similar to prettier, which can be controlled with the typePrintWidth option to determine when types should be wrapped.

Along with this change, TypeDoc will now be smarter when deciding whether or not to recurse into types to render additional details about them. This is most obvious when viewing documentation for functions which accept or return functions or objects with functions. TypeDoc will still render the full details if it detects that there is additional details provided via documentation comments (either directly or via @expand) within the type.

Old New
Note: This is only about half of the rendered signature

Alerts

GitHub supports alerts to call out important information. TypeDoc now supports the same format in comments and markdown documents and will render them in a similar way.

image

Outputs

TypeDoc supports both HTML and JSON outputs, but if a plugin (e.g. typedoc-plugin-markdown) wanted to add an additional output type, there wasn't an obvious place to hook into the API to expose it to users. TypeDoc now supports the idea of a generic output for a project, which also makes it possible to render TypeDoc's output multiple times with different settings.

The options key is optional, and may include any TypeDoc option, though users should be aware that options which are used during conversion will be effectively ignored if set under outputs.

// typedoc.json
{
    "outputs": [
        {
            "name": "html",
            "path": "../docs"
        },
        {
            "name": "html",
            "path": "../docs-grouped-nav",
            "options": {
                "navigation": true
            }
        },
        {
            "name": "json",
            "path": "../docs/docs.json"
        }
    ],
}

Change Log

Breaking Changes

Features

Bug Fixes

Gerrit0 commented 12 hours ago

I was hoping to get this out with the TS release, but want to give a few days to update plugins, as the past couple weeks have kept me entirely too busy, so I didn't get the rest of 0.27 finished until just a few minutes ago... sorry about that! The downside of hobby projects..

Planning on Monday/Tuesday for this release now.

0.27.0-beta.1