Library › Coding AI › College students
Write a generic TypeScript stub with exact JSDoc lines
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Your team is splitting a utils file: you write signatures, Priya writes bodies. Write a stub for groupBy with exactly this signature: export function groupBy<T, K extends PropertyKey>(items: readonly T[], keyOf: (item: T) => K): Record<K, T[]>. Above it, a JSDoc block with a one-line summary and exactly the tags @param items, @param keyOf and @returns. The body is only throw new Error("TODO: Priya"). Exactly 1 code block of at most 10 lines, under 20 words of text.
Common mistakes when you ask AI for this
- Getting an implementation. The AI writes the reduce loop, which is Priya's task. Try: Say: "Stub only: the body is throw new Error(\"TODO: Priya\")."
- A slightly different signature. The AI picks its own names or drops readonly, so the UI team codes against the wrong thing. Try: Paste the exact signature.
- Off-convention docs. The AI adds an @example block or skips @returns. Try: Add: "JSDoc: one-line summary, @param items, @param keyOf, @returns. No @example."
- Extras around it. The AI explains generics and suggests lodash. Try: Add: "One code block, no text."
What a strong prompt includes
- Asks for a stub
- Gives the signature
- Specifies the JSDoc
- Rules out @example
- Limits the reply
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)