krisztianb / typedoc-plugin-replace-text

Plugin for TypeDoc that replaces text in the documentation
ISC License
5 stars 2 forks source link

Include typings in package #6

Closed whazor closed 1 year ago

whazor commented 1 year ago

Hi, could you please export the typescript typings (or source) into dist/? This would help me with typing the configuration.

Currently, there are only JS files: image

Thanks!

krisztianb commented 1 year ago

Hi. Could you explain what exactly you are trying to do?

whazor commented 1 year ago

I was trying to add types to the configuration file, but for this library the types are not published.

krisztianb commented 1 year ago

Ok. How are you trying to do this? I'm asking because I haven't seen a TypeDoc plugin that publishes its typings.

whazor commented 1 year ago

My goal is to add typings to the configuration.

I think I was trying something like:

/** @type {import('typedoc').TypeDocOptions & import('typedoc-plugin-replace-text').TypeDocOptionMap} */
module.exports = {
    out: "output",
    entryPointStrategy: "expand",
    entryPoints: ["input/module1.ts", "input/module2.ts"],
    tsconfig: "tsconfig.json",
    readme: "MAIN.md",
    plugin: ["typedoc-plugin-replace-text"],
    replaceText: {
        inCodeCommentText: true,
        inCodeCommentTags: true,
        inIncludedFiles: true,
        replacements: [
            {
                pattern: "(GH-(\\d+))",
                replace: "[$1](https://github.com/your-name/the-repo/issues/$2)"
            },
            {
                pattern: "King Kong",
                flags: "gi",
                replace: (match) => {
                    return match + " is the greatest!";
                },
            },
        ],
    },
};
krisztianb commented 1 year ago

Oh I see. That looks like a good idea. However I don't think that will work, because the type that you are importing is actually just a declaration merger used by the plugin to integrate with TypeDoc.

However I should be able to export the type of the plugin's options object in a different manner so that you can use it in you configuration. I'm going to take a closer look and let you know soon.

krisztianb commented 1 year ago

Finally I got around doing this. It is released with version 3.1.0.

It will work the way you were using it in your example with one small difference:

/** @type { import('typedoc').TypeDocOptionMap & import('typedoc-plugin-replace-text').Config } */

You need to use import('typedoc').TypeDocOptionMap instead of import('typedoc').TypeDocOptions because TypeDoc is using conditional types in TypeDocOptions which aren't resolved correctly when intersected with other types.

Please check it out and give me feedback. Thank you.