-
Notifications
You must be signed in to change notification settings - Fork 0
Typedoc Documentation Guide
This guide explains how to set up, generate, and maintain API documentation for your project using TypeDoc. It includes configuration options, best practices, and troubleshooting tips.
TypeDoc is a documentation generator for TypeScript projects. It extracts API information from your code and produces a static HTML site. With plugins like typedoc-plugin-vue
, TypeDoc can also handle Vue Single File Components (SFCs).
Each function in this project is documented using TSDoc comments within its respective file. Developers should refer directly to the relevant TypeScript files for function details:
-
API-related functions →
store/geoserver.ts
,store/participation.ts
-
Filtering functions →
components/Map/Layer/Filter/AttributeFiltering.vue
,GeometryFiltering.vue
-
State management functions →
store/map.ts
,store/filter.ts
For a complete breakdown of function parameters and usage, refer to the respective files.
- Your project is written in TypeScript.
- If you use Vue SFCs, install
typedoc-plugin-vue
. - A valid
tsconfig.json
that includes your source files (e.g.,src/**/*.ts
,src/**/*.tsx
,src/**/*.vue
).
Install TypeDoc and the Vue plugin as development dependencies:
npm install --save-dev typedoc typedoc-plugin-vue
Create a typedoc.json
file in your project root. Below is an example configuration that excludes test files and a specific presets folder:
{
"entryPoints": ["src"],
"entryPointStrategy": "expand",
"out": "docs",
"exclude": ["**/*.test.ts", "src/presets/**"],
"tsconfig": "tsconfig.json",
"plugin": ["typedoc-plugin-vue"],
"excludeVueProperties": true
}
-
entryPoints
: Specifies the starting point for documentation generation. Here, the entiresrc
directory is used. -
entryPointStrategy
: Setting this toexpand
tells TypeDoc to recursively include all files undersrc
that match yourtsconfig.json
include patterns. -
out
: The output directory for the generated documentation (in this case,docs
). -
exclude
: Patterns for files or directories to exclude (e.g., test files and presets). -
tsconfig
: Ensures TypeDoc uses the same TypeScript compiler options as your project. -
plugin
: Loadstypedoc-plugin-vue
to enable processing of Vue SFCs. -
excludeVueProperties
: Omits internal Vue properties (e.g.,$props
,$emit
) from the generated documentation.
Once your configuration is in place, generate the documentation:
npx typedoc
This command uses your typedoc.json
settings to generate the documentation in the docs
folder.
For convenience, add a script so users can generate documentation easily:
{
"scripts": {
"docs": "typedoc",
"dev": "vite",
"build": "vite build",
"start": "vite preview"
}
}
Now, running:
npm run docs
will generate or update the documentation.
-
Separate Documentation Generation: Keep documentation generation separate (
npm run docs
) to avoid slowing down development (npm run dev
) or production builds (npm run build
). - Automate Updates: Consider integrating documentation generation into your CI/CD pipeline to keep it up to date with code changes.
-
Host Your Documentation: Deploy the
docs
folder to GitHub Pages, Netlify, or Vercel for easy access. - Use JSDoc/TSDoc Comments: Improve generated docs by adding comments to functions, classes, and exported members.
-
Exclude Non-Essential Files: Use
exclude
intypedoc.json
to omit test files and experimental code.
If you receive this warning:
The entry point … is not referenced by the ‘files’ or ‘include’ option in your tsconfig
Ensure your tsconfig.json
includes paths for your source files. You may need to adjust your typedoc.json
or run TypeDoc with --entryPointStrategy expand
.
Ensure you have a Vue shims file (src/shims-vue.d.ts
) so TypeScript can process .vue
files correctly. A typical shims file:
// src/shims-vue.d.ts
declare module "*.vue" {
import { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any>;
export default component;
}
By following this guide, you can efficiently set up and maintain comprehensive API documentation for your TypeScript (and Vue) projects using TypeDoc. Keeping your documentation updated and accessible benefits both developers and users.
Happy documenting! 🚀
Welcome to the TOSCA Wiki! You'll find both user and developer documentation here.