Loading...
Loading...
Use when documenting public APIs. Use when writing library code. Use when using JSDoc-style comments. Use when generating documentation. Use when explaining complex types.
npx skill4agent add marius-townhouse/effective-typescript-skills tsdoc-comments@template// RED FLAGS - Missing documentation
export function process(data: unknown): Result; // What does it do?
export type Transform<T> = /* complex type */; // What's T for?
export class ApiClient { // How do I use this?
constructor(config: Config) {}
}/**
* Short description of what this does.
*
* Longer explanation if needed. Explain why this exists,
* when to use it, and any important caveats.
*
* @param paramName - Description of parameter
* @returns Description of return value
* @example
* ```typescript
* const result = myFunction('input');
* console.log(result); // 'processed: input'
* ```
*/
function myFunction(input: string): string {
return `processed: ${input}`;
}/**
* Fetches user data from the API.
*
* Automatically handles authentication and retries failed requests
* up to 3 times with exponential backoff.
*
* @param userId - The unique identifier for the user
* @param options - Optional configuration for the request
* @returns A promise that resolves to the user data
* @throws {ApiError} When the user is not found or the request fails
* @example
* ```typescript
* const user = await fetchUser('123');
* console.log(user.name);
* ```
*/
async function fetchUser(
userId: string,
options?: FetchOptions
): Promise<User> {
// Implementation
}/**
* Creates a partial version of a type where all properties are optional.
*
* @template T - The type to make partial
* @example
* ```typescript
* interface User {
* name: string;
* age: number;
* }
*
* type PartialUser = Partial<User>;
* // { name?: string; age?: number; }
* ```
*/
type MyPartial<T> = {
[K in keyof T]?: T[K];
};/**
* Client for interacting with the REST API.
*
* Handles authentication, request retries, and response parsing.
* Create one instance per application and reuse it.
*
* @example
* ```typescript
* const client = new ApiClient({
* baseUrl: 'https://api.example.com',
* apiKey: process.env.API_KEY
* });
*
* const users = await client.users.list();
* ```
*/
export class ApiClient {
/**
* Creates a new API client instance.
*
* @param config - Configuration options for the client
*/
constructor(config: ClientConfig) {}
/**
* Resources for managing users.
*/
readonly users: UserResource;
}/**
* Description of the function.
*
* @param name - Parameter description
* @returns Return value description
* @throws {ErrorType} When/why this error is thrown
* @example Code example showing usage
* @deprecated Use newFunction instead. Will be removed in v2.0.
* @see Related function or documentation
* @internal For internal use only, not part of public API
*/
// For generic types:
/**
* @template T - Description of type parameter
* @template K - Description of second parameter
*/
// For class members:
/**
* @readonly This property is read-only
* @protected This member is protected
*/| Anti-Pattern | Problem | Solution |
|---|---|---|
| No documentation | Users guess at usage | Add TSDoc comments |
| "Obvious" comments | | Explain why, not what |
| Outdated docs | Misleading users | Update with code changes |
| Missing @template | Generics unexplained | Document type parameters |
| Tag | Use For |
|---|---|
| Function parameters |
| Return value description |
| Generic type parameters |
| Usage examples |
| Exceptions thrown |
| Mark deprecated APIs |
| Related documentation |