TypeStrong / typedoc

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

How to use @module (with sub-modules)? #2405

Closed Tobjoern closed 12 months ago

Tobjoern commented 12 months ago

Question

I'm currently documenting an older project, which features a quite nested structure. My idea is to declare nested modules, i.e. '/classes', '/classes/users', '/classes/users/resolvers', ...

To achieve this, I tried to use the '@module' tag and reproduce the example given in the documentation. Here is a small excerpt of the code:

/**
 * This is the doc comment for thing1/functions.ts
 *
 * Specify this is a module comment and rename it to thing1:
 * @module thing1
 */
export * from "./thing1/functions";

From my understanding, this should create a module 'thing1', which holds everything, which is exported from the './thing/functions' TS file. However, all the exported functions are simply added to the 'root' module, when looking at the generated ui.

I also created a reproduction here: https://github.com/Tobjoern/typedoc-module-repro

Since I'm new to the project, I most likely made some mistake in the setup. My question is, how do I get the @module tag to work, and how can I most effectively display a deeply nested folder structure with typedoc?

Your help is highly appreciated.

Gerrit0 commented 12 months ago

This is not what @module is for, it is only for renaming an entry point which TypeDoc gets wrong.

You probably want

/**
 * Doc
 */
export * as thing1 from "./thing1/functions"
Tobjoern commented 12 months ago

This is not what @module is for, it is only for renaming an entry point which TypeDoc gets wrong.

You probably want

/**
 * Doc
 */
export * as thing1 from "./thing1/functions"

Thanks for your help. I adjusted the code in the way you described, but I still don't get the module 'thing1' to show up.

Gerrit0 commented 12 months ago

image

Going to need more info than that then.. seems to create a namespace for me.

diff --git a/src/index.ts b/src/index.ts
index 4595237..0207a39 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -9,8 +9,5 @@ export * from "./internals";

 /**
  * This is the doc comment for thing1/functions.ts
- *
- * Specify this is a module comment and rename it to thing1:
- * @module thing1
  */
-export * from "./thing1/functions";
\ No newline at end of file
+export * as thing1 from "./thing1/functions";

Alternatively, specifying multiple entry points:

image

diff --git a/src/index.ts b/src/index.ts
index 4595237..e4b7f59 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -7,10 +7,3 @@ export * from "./showcase";
 export * from "./reactComponents";
 export * from "./internals";

-/**
- * This is the doc comment for thing1/functions.ts
- *
- * Specify this is a module comment and rename it to thing1:
- * @module thing1
- */
-export * from "./thing1/functions";
\ No newline at end of file
diff --git a/src/thing1/functions.ts b/src/thing1/functions.ts
index 8296110..1d41dca 100644
--- a/src/thing1/functions.ts
+++ b/src/thing1/functions.ts
@@ -1,3 +1,5 @@
+/** @module thing1 */
+
 /**
  * Calculates the square root of a number.
  *
diff --git a/typedoc.json b/typedoc.json
index 184f569..16b38ec 100644
--- a/typedoc.json
+++ b/typedoc.json
@@ -2,7 +2,8 @@
     "$schema": "https://typedoc.org/schema.json",
     "name": "TypeDoc Example",
     "entryPoints": [
-        "./src"
+        "./src",
+   "./src/thing1/functions.ts"
     ],
     "sort": [
         "source-order"
@@ -23,4 +24,4 @@
     "sidebarLinks": {
         "API": "https://typedoc.org/api"
     },
-}
\ No newline at end of file
+}
Tobjoern commented 12 months ago

Thanks, using named exports like export * as thing1 from "./thing1/functions"; or export * as subModule from './submodule/index'

Fixed the issue for me.