microsoft / microsoft/TypeScript
JsDoc with overloads and different generics results in wrong dts output
Open
Nobody has claimed this yet.
Bug
Domain: JSDoc
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 Search Terms
javascript jsdoc dts overload
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about jsdoc
⏯ Playground Link
💻 Code
/**
* @template {string} Element
* @overload
* @param {Element} element
* @returns {() => void}
*/
/**
* @template {boolean} Element
* @overload
* @param {Element} element
* @returns {() => void}
*/
/**
* @overload
* @param {number} element
* @returns {() => void}
*/
/**
* @param {any} element
*/
export function on(element) {
return () => {}
}
🙁 Actual behavior
The resulting dts of the given JSDoc looks like this:
export function on<Element extends string>(element: Element): () => void;
export function on<Element extends string>(element: Element): () => void;
export function on(element: number): () => void;
As you can see the generic does extends string both times, but it should be extends boolean the second time
🙂 Expected behavior
export function on<Element extends string>(element: Element): () => void;
export function on<Element extends boolean>(element: Element): () => void;
export function on(element: number): () => void;
Additional information about the issue
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground reproduction and inspect how the three JSDoc overloads are converted into the generated .d.ts output. Verify that each overload preserves its own generic constraint, especially the second overload's extends boolean, and confirm the output matches the expected declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100