| name | jsdoc-typescript-docs |
| description | Documents TypeScript code with JSDoc comments, generates API documentation, and creates type-safe documentation. Use when users request "JSDoc", "code documentation", "API docs", "TypeDoc", or "inline documentation". |
JSDoc TypeScript Documentation
Create comprehensive inline documentation for TypeScript codebases.
Core Workflow
- Document functions: Parameters, returns, examples
- Document types: Interfaces, types, enums
- Add descriptions: Purpose and usage
- Include examples: Code samples
- Generate docs: TypeDoc output
- Integrate CI: Automated doc generation
Function Documentation
Basic Function
export function calculateTotal(price: number, taxRate: number): number {
return price * (1 + taxRate);
}
Async Function
export async function fetchUser(
userId: string,
options?: FetchOptions
): Promise<User> {
const response = await fetch(`/api/users/${userId}`, options);
if (response.status === 404) {
throw new NotFoundError(`User ${userId} not found`);
}
if (!response.ok) {
throw new NetworkError('Failed to fetch user');
}
return response.json();
}
Generic Function
export function filterArray<T>(
array: T[],
predicate: (item: T, index: number) => boolean
): T[] {
return array.filter(predicate);
}
Overloaded Function
export function format(value: number): string;
export function format(value: number, formatStr: string): string;
export function format(value: number, formatStr?: string): string {
if (formatStr === 'currency') {
return `$${value.toFixed(2)}`;
}
if (formatStr === 'percent') {
return `${(value * 100).toFixed(1)}%`;
}
return value.toString();
}
Interface Documentation
export interface User {
id: string;
email: string;
name: string;
role: 'admin' | 'user' | 'guest';
createdAt: Date;
updatedAt?: Date;
profile?: UserProfile;
}
export interface UserProfile {
avatarUrl?: string;
language: string;
timezone: string;
notifications: NotificationSettings;
}
Type Documentation
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
export type RequestConfig<TBody = unknown> = {
method: HttpMethod;
headers?: Record<string, string>;
body?: TBody;
timeout?: number;
retries?: number;
};
export type Result<T, E = Error> =
| { success: true; data: T }
| { success: false; error: E };
Class Documentation
export class ApiClient {
readonly baseUrl: string;
static create(config: ApiClientConfig): ApiClient {
return new ApiClient(config);
}
private constructor(private config: ApiClientConfig) {
this.baseUrl = config.baseUrl;
}
async get<T>(endpoint: string, options?: RequestOptions): Promise<T> {
return this.request<T>('GET', endpoint, options);
}
async post<T, TBody = unknown>(
endpoint: string,
body: TBody,
options?: RequestOptions
): Promise<T> {
return this.request<T>('POST', endpoint, { ...options, body });
}
private async request<T>(
method: HttpMethod,
endpoint: string,
options?: RequestOptions
): Promise<T> {
}
}
Enum Documentation
export enum OrderStatus {
Pending = 'pending',
Processing = 'processing',
Shipped = 'shipped',
Delivered = 'delivered',
Cancelled = 'cancelled',
Returned = 'returned',
}
React Component Documentation
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'outline' | 'ghost';
size?: 'sm' | 'md' | 'lg';
loading?: boolean;
leftIcon?: React.ReactNode;
rightIcon?: React.ReactNode;
}
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ variant = 'primary', size = 'md', loading, children, ...props }, ref) => {
}
);
Button.displayName = 'Button';
TypeDoc Configuration
{
"entryPoints": ["./src/index.ts"],
"out": "./docs",
"name": "My Library",
"readme": "./README.md",
"plugin": [
"typedoc-plugin-markdown",
"typedoc-plugin-mdn-links"
],
"excludePrivate": true,
"excludeProtected": true,
"excludeInternal": true,
"includeVersion": true,
"categorizeByGroup": true,
"categoryOrder": ["Core", "Utilities", "Types", "*"],
"navigationLinks": {
"GitHub": "https://github.com/user/repo",
"npm": "https://www.npmjs.com/package/my-package"
},
"validation": {
"notExported": true,
"invalidLink": true,
"notDocumented": false
}
}
{
"scripts": {
"docs": "typedoc",
"docs:watch": "typedoc --watch"
},
"devDependencies": {
"typedoc": "^0.25.0",
"typedoc-plugin-markdown": "^3.17.0",
"typedoc-plugin-mdn-links": "^3.1.0"
}
}
JSDoc Tags Reference
Best Practices
- Document public API: All exports need docs
- Use examples: Show real usage
- Describe parameters: Clear, concise descriptions
- Document errors: What can be thrown
- Link related items: Use @see tags
- Keep updated: Sync docs with code
- Generate HTML: TypeDoc for browsable docs
- Validate in CI: Check for missing docs
Output Checklist
Every documented codebase should include: