| name | typescript-docs |
| version | 1.0.0 |
| description | Generates comprehensive TypeScript documentation using JSDoc, TypeDoc, and multi-layered documentation patterns for different audiences. Use when creating API documentation, architectural decision records (ADRs), code examples, and framework-specific patterns for NestJS, Express, React, Angular, and Vue. |
| allowed-tools | Read, Write, Edit, Bash, Grep, Glob |
| category | frontend |
| tags | ["typescript","documentation","jsdoc","typedoc","api-docs","adr","react","angular","vue","nestjs","express"] |
TypeScript Documentation Skill
Overview
Deliver production-ready TypeScript documentation that serves multiple audiences through layered documentation architecture. Generate API docs with TypeDoc, create architectural decision records, and maintain comprehensive code examples.
When to Use
- "generate TypeScript API docs" - Create TypeDoc configuration and generate documentation
- "document this TypeScript module" - Add comprehensive JSDoc to a module
- "create ADR for TypeScript decision" - Document architectural decisions
- "setup documentation pipeline" - Configure automated documentation generation
- "document React component" - Create component documentation with examples
- "create API reference" - Generate comprehensive API documentation
Instructions
- Configure TypeDoc: Set up typedoc.json with entry points and output settings
- Add JSDoc Comments: Document all public APIs with @param, @returns, @example
- Create ADRs: Document architectural decisions with context and consequences
- Set Up Pipeline: Configure CI/CD for automated documentation generation
- Write Examples: Include runnable code examples for complex functions
- Cross-Reference: Use @see and @link to connect related documentation
- Validate Docs: Run ESLint with JSDoc rules to ensure completeness
Examples
Documenting a Service Class
@Injectable()
export class AuthService {
async login(credentials: LoginCredentials): Promise<AuthResult> {
}
}
Constraints and Warnings
- Private Members: Use @private or exclude from TypeDoc output
- Complex Types: Document generic constraints and type parameters
- Breaking Changes: Use @deprecated with migration guidance
- Security Info: Never include secrets or credentials in documentation
- Link Validity: Ensure @see references point to valid locations
- Example Code: All examples should be runnable and tested
- Versioning: Keep documentation in sync with code versions
Quick Start
- Install TypeDoc and related tools:
npm install --save-dev typedoc typedoc-plugin-markdown
npm install --save-dev @compodoc/compodoc
- Create basic TypeDoc configuration:
{
"entryPoints": ["src/index.ts"],
"out": "docs/api",
"theme": "markdown",
"excludePrivate": true,
"readme": "README.md"
}
- Generate documentation:
npx typedoc
Core Documentation Patterns
1. JSDoc Best Practices
Interface Documentation
export interface User {
id: string;
email: string;
roles: UserRole[];
metadata: Record<string, unknown>;
}
Function Documentation
export async function authenticateUser(
email: string,
password: string,
options?: AuthOptions
): Promise<AuthResult> {
}
Class Documentation
export class AuthService {
constructor(private readonly config: AuthConfig) {}
async login(credentials: LoginCredentials): Promise<AuthResult> {
}
}
2. Advanced TypeScript Documentation
Generic Constraints
export abstract class BaseRepository<T extends BaseEntity, K extends string | number> {
abstract findById(id: K): Promise<Result<T, RepositoryError>>;
}
Union Types and Discriminated Unions
export type ApiResponse<T> =
| { status: 'success'; data: T }
| { status: 'error'; error: ApiError }
| { status: 'pending'; progress?: number };
3. Framework-Specific Documentation
NestJS Documentation
@Injectable()
export class JwtAuthGuard implements CanActivate {
constructor(private jwtService: JwtService) {}
async canActivate(context: ExecutionContext): Promise<boolean> {
}
}
React Component Documentation
export const UserProfile = React.memo<UserProfileProps>(
({ user, editable, onEdit }) => {
}
);
Express Middleware Documentation
export function rateLimit(options: RateLimitOptions): RequestHandler {
}
Architectural Decision Records (ADRs)
ADR Template
# ADR-001: TypeScript Strict Mode Configuration
## Status
Proposed | Accepted | Rejected | Deprecated | Superseded
## Context
What is the issue that we're seeing that is motivating this decision?
## Decision
What is the change that we're proposing and/or doing?
## Consequences
What becomes easier or more difficult to do because of this change?
## Compliance
- Links to standards or regulations
- Impact on compliance requirements
## References
- [TypeScript Strict Mode Documentation](https://www.typescriptlang.org/tsconfig#strict)
- [Related ADRs](#)
Sample ADR
# ADR-003: NestJS Framework Selection for Backend API
## Status
Accepted
## Context
Our Express.js monolith has grown to 50k+ lines with:
- Inconsistent error handling patterns
- No standardized validation
- Difficult testing due to tight coupling
- Poor TypeScript integration
We need a framework that provides:
- Strong TypeScript support
- Opinionated structure
- Built-in validation and error handling
- Excellent testing support
- Microservices readiness
## Decision
Adopt NestJS for all new backend services with:
- Full TypeScript strict mode
- Class-based DI container
- Modular architecture
- Built-in validation pipes
- Exception filters
- Swagger/OpenAPI integration
## Consequences
### Positive
- 40% reduction in boilerplate code
- Consistent patterns across services
- Improved testability with dependency injection
- Better developer experience with decorators
- Built-in support for microservices
### Negative
- Learning curve for team (2-3 weeks)
- More complex for simple APIs
- Requires understanding of decorators
- Additional build step needed
## Implementation
1. Create NestJS starter template
2. Migrate new services to NestJS
3. Gradually refactor critical Express services
4. Establish NestJS best practices guide
## Compliance
- Aligns with architecture standards v2.1
- Supports SOC2 through better error handling
- Enables GDPR compliance with structured logging
Documentation Generation Pipeline
TypeDoc Configuration
{
"entryPoints": ["src/index.ts"],
"out": "docs/api",
"theme": "markdown",
"readme": "README.md",
"excludePrivate": true,
"excludeProtected": false,
"excludeExternals": true,
"includeVersion": true,
"sort": ["source-order"],
"kindSortOrder": [
"Document",
"Project",
"Module",
"Namespace",
"Enum",
"Class",
"Interface",
"TypeAlias",
"Constructor",
"Property",
"Method"
],
"categorizeByGroup": true,
"categoryOrder": [
"Authentication",
"Authorization",
"*",
"Other"
],
"navigation": {
"includeCategories": true,
"includeGroups": true
}
}
Documentation Scripts
{
"scripts": {
"docs:generate": "typedoc",
"docs:serve": "cd docs && python -m http.server 8080",
"docs:validate": "node scripts/validate-docs.js",
"docs:deploy": "npm run docs:generate && ./scripts/deploy-docs.sh",
"adr:new": "node scripts/create-adr.js",
"adr:generate-index": "node scripts/generate-adr-index.js"
}
}
GitHub Actions Workflow
name: Documentation
on:
push:
branches: [main, develop]
paths:
- 'src/**'
- 'docs/**'
- '.github/workflows/docs.yml'
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Generate TypeDoc
run: npm run docs:generate
- name: Validate documentation
run: npm run docs:validate
- name: Check for documentation changes
id: changes
run: |
if git diff --quiet HEAD~1 docs/; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit documentation
if: steps.changes.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add docs/
git commit -m "docs: update generated documentation [skip ci]"
git push
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
Framework-Specific Documentation
NestJS Documentation Patterns
export const RateLimit = (options: RateLimitOptions) =>
applyDecorators(
UseInterceptors(RateLimitInterceptor),
SetMetadata('rateLimit', options)
);
React Documentation Patterns
export function useForm<T>({
schema,
initialValues
}: UseFormOptions<T>): UseFormReturn<T> {
}
Angular Documentation Patterns
@Injectable({
providedIn: 'root'
})
export class AuthService {
}
Documentation Validation
TypeDoc Plugin for Validation
export function load(app) {
app.converter.on(
Converter.EVENT_CREATE_SIGNATURE,
(context, reflection, node?) => {
if (reflection.kind === ReflectionKind.Method) {
const comment = reflection.comment;
if (!comment) {
app.logger.warn(
`Method ${reflection.name} lacks documentation in ${reflection.parent.name}`
);
}
}
}
);
}
ESLint Rules for Documentation
{
"rules": {
"jsdoc/require-description": "error",
"jsdoc/require-param-description": "error",
"jsdoc/require-returns-description": "error",
"jsdoc/require-example": "warn",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/tag-lines": ["error", "any", { "startLines": 1 }]
}
}
Best Practices
- Document Public APIs: All public methods, classes, and interfaces
- Use @example: Provide runnable examples for complex functions
- Include @throws: Document all possible errors
- Add @see: Cross-reference related functions/types
- Use @remarks: Add implementation details and notes
- Document Generics: Explain generic constraints and usage
- Include Performance Notes: Document time/space complexity
- Add Security Warnings: Highlight security considerations
- Use Categories: Group related documentation
- Keep Updated: Update docs when code changes
Common Pitfalls to Avoid
- Don't document obvious code: Focus on why, not what
- Avoid outdated examples: Keep examples current
- Don't skip error cases: Document all @throws scenarios
- Avoid generic descriptions: Be specific to your implementation
- Don't ignore edge cases: Document special conditions
- Avoid broken links: Keep @see references valid
- Don't use unclear language: Write for your audience
- Avoid duplication: Link to related docs instead of repeating