Reading Library Documentation
5 exercises on function signatures, JSDoc annotations, TypeScript types, return values, and Caveats sections in real library docs.
Key patterns for reading library documentation
- Read
@paramand@returnscarefully — both the success and failure paths ?after a parameter name means it is optional; defaults apply if omitted- Caveats sections contain the most important warnings — read them first
- Examples show one common path; the signature shows all possible inputs
0 / 5 completed
1 / 5
Read the following function signature from a library's documentation:
If
/**
* Retries an async function up to `maxAttempts` times.
*
* @param fn - The async function to retry. Receives the attempt number (1-based).
* @param options - Configuration object.
* @param options.maxAttempts - Maximum number of attempts. Default: 3.
* @param options.delayMs - Base delay between attempts in milliseconds. Default: 500.
* @param options.backoff - Multiply delay by this factor each attempt. Default: 2.
* @returns Promise that resolves with the return value of `fn` on success,
* or rejects with the last error after all attempts are exhausted.
*
* @example
* const data = await retry(
* async (attempt) => fetchUser(userId),
* { maxAttempts: 5, delayMs: 200, backoff: 1.5 }
* );
*/
function retry<T>(fn: (attempt: number) => Promise<T>, options?: RetryOptions): Promise<T>If
maxAttempts is 5 and all 5 attempts fail, what does the function return?The function rejects with the last error after all attempts are exhausted.
The JSDoc explicitly states: "rejects with the last error after all attempts are exhausted." This is the standard retry-exhaustion pattern: save the most recent error and re-throw it so the caller knows why the final attempt failed.
Reading JSDoc @returns tags: The
Retry pattern vocabulary:
The JSDoc explicitly states: "rejects with the last error after all attempts are exhausted." This is the standard retry-exhaustion pattern: save the most recent error and re-throw it so the caller knows why the final attempt failed.
Reading JSDoc @returns tags: The
@returns (or @return) block documents the success path AND the failure path. Always read both halves — the "resolves with" and the "rejects with."Retry pattern vocabulary:
- exponential backoff — doubling the wait time on each failure (here: delay × backoff factor)
- jitter — adding randomness to backoff to avoid thundering-herd on retries
- idempotent — safe to retry without side effects (e.g. a GET request vs. a payment)
- exhausted — all attempts have been used up
- transient error — a temporary failure worth retrying (network blip, rate limit)