Adopt a rule that comments/JSDoc/API docs must be both correct and useful at the point of use—never misleading, stale, or attached to the wrong symbol.
Apply this checklist:
/** ... */ block is positioned so TypeScript attaches it to the intended declaration; avoid duplicate/orphaned JSDoc blocks.yield/API boundary.t('...') keys must be added to all locales.Example: document generator consumption when yielding views into a reused buffer
async function* readFileHandleChunks(fileHandle: FileHandle, sourceSize: number): AsyncGenerator<Buffer> {
const highWaterMark = 512 * 1024;
const buffer = Buffer.allocUnsafe(highWaterMark);
let position = 0;
while (position < sourceSize) {
const bytesRead = (await fileHandle.read(buffer, 0, Math.min(highWaterMark, sourceSize - position), position)).bytesRead;
if (bytesRead === 0) return;
position += bytesRead;
// CONTRACT: This is a view into a reused underlying buffer.
// Consumers must synchronously copy/consume the bytes before the next `yield`.
yield buffer.subarray(0, bytesRead);
}
}
If you make a behavioral change (output strings, semantics, validation rules, or i18n keys), treat documentation/comment updates as part of the same change set—otherwise the next developer will be guided by false information.
Enter the URL of a public GitHub repository