Skip to content

Starlight TypeDoc - Tự động Generate Documentation từ TypeScript

Starlight TypeDoc (starlight-typedoc) là một plugin cho phép tự động generate tài liệu documentation từ TypeScript code sử dụng TypeDoc.

ApproachƯu điểmNhược điểm
Viết MDX thủ côngLinh hoạt, control hoàn toànTốn thời gian
starlight-typedocTự động, sync với codeÍt linh hoạt về layout
  • Dự án có nhiều TypeScript interfaces, types cần document
  • Library/framework cần API docs tự động
  • Muốn docs luôn sync với code
  • Tài liệu hướng dẫn (vẫn nên viết thủ công)
  • Docs cần nhiều custom styling
  • Code ít, chủ yếu là nội dung giải thích
Terminal window
npm install @zenoo/typedoc-plugin-starlight

Cấu hình trong astro.config.mjs:

import starlight from '@astrojs/starlight';
import starlightTypeDoc from 'starlight-typedoc';
export default defineConfig({
integrations: [
starlight({
title: 'My Docs',
plugins: [
starlightTypeDoc({
entryPoints: ['../src/**/*.ts'],
}),
],
}),
],
});
  1. Viết TypeScript code với JSDoc comments
  2. Chạy npm run build
  3. Plugin tự động generate trang docs từ code
/**
* Calculate the sum of two numbers
* @param a - First number
* @param b - Second number
* @returns Sum of a and b
*/
function add(a: number, b: number): number {
return a + b;
}

Sẽ tự động tạo thành trang documentation với description, parameters, return type.

  • starlight-typedoc: Phù hợp cho API documentation tự động
  • MDX thủ công: Phù hợp cho tutorials và hướng dẫn
  • Có thể kết hợp cả hai: dùng typedoc cho API, MDX cho guides